qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] implement strnlen for systems that need it
@ 2017-10-20  1:50 John Arbuckle
  2017-10-20  9:25 ` David Gibson
  2017-10-20  9:38 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: John Arbuckle @ 2017-10-20  1:50 UTC (permalink / raw)
  To: qemu-ppc, qemu-devel, david; +Cc: John Arbuckle

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
 Makefile.dtc           |  3 ++-
 libfdt/Makefile.libfdt |  2 +-
 libfdt/libfdt_env.h    | 12 ++++++++++++
 libfdt/strnlen.h       | 14 ++++++++++++++
 strnlen.c              | 25 +++++++++++++++++++++++++
 5 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 libfdt/strnlen.h
 create mode 100644 strnlen.c

diff --git a/Makefile.dtc b/Makefile.dtc
index bece49b..14eaa4e 100644
--- a/Makefile.dtc
+++ b/Makefile.dtc
@@ -12,7 +12,8 @@ DTC_SRCS = \
 	livetree.c \
 	srcpos.c \
 	treesource.c \
-	util.c
+	util.c \
+    strnlen.c
 
 DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
 DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
diff --git a/libfdt/Makefile.libfdt b/libfdt/Makefile.libfdt
index 098b3f3..b20a85b 100644
--- a/libfdt/Makefile.libfdt
+++ b/libfdt/Makefile.libfdt
@@ -7,5 +7,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
 LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
 LIBFDT_VERSION = version.lds
 LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
-	fdt_addresses.c fdt_overlay.c
+	fdt_addresses.c fdt_overlay.c strnlen.c
 LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h
index 952056c..a25a615 100644
--- a/libfdt/libfdt_env.h
+++ b/libfdt/libfdt_env.h
@@ -109,4 +109,16 @@ static inline fdt64_t cpu_to_fdt64(uint64_t x)
 #undef CPU_TO_FDT16
 #undef EXTRACT_BYTE
 
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+
+#define MAC_OS_X_VERSION_10_7 1070
+
+/* strnlen() is not available on Mac OS < 10.7 */
+# if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
+#include "strnlen.h"
+#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) */
+
+#endif /* __APPLE__ */
+
 #endif /* _LIBFDT_ENV_H */
diff --git a/libfdt/strnlen.h b/libfdt/strnlen.h
new file mode 100644
index 0000000..62a45c0
--- /dev/null
+++ b/libfdt/strnlen.h
@@ -0,0 +1,14 @@
+/*
+ * File: strnlen.h
+ * Date: 10-19-2017
+ * Description: Implements functions that may be missing on the host system
+ */
+
+#ifndef STRNLEN
+#define STRNLEN
+
+#include <stddef.h>
+
+size_t strnlen(const char *string, size_t max_count);
+
+#endif /* STRNLEN */
diff --git a/strnlen.c b/strnlen.c
new file mode 100644
index 0000000..3559c6f
--- /dev/null
+++ b/strnlen.c
@@ -0,0 +1,25 @@
+/*
+ * File: strnlen.c
+ * Date: 10-19-2017
+ * Description: Implement the strnlen() function for platforms that need it
+ */
+
+#include <stddef.h>
+#include "strnlen.h"
+
+/* 
+ * strnlen: returns the length of a string or max_count - which ever is smallest
+ * Input 1 string: the string whose size is to be determined
+ * Input 2 max_count: the maximum value returned by this function
+ * Output: length of the string or max_count (the smallest of the two)
+ */
+size_t strnlen(const char *string, size_t max_count)
+{
+    int count;
+    for(count = 0; count < max_count; count++) {
+        if (string[count] == '\0') {
+            break;
+        }
+    }
+    return count;
+}
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] implement strnlen for systems that need it
  2017-10-20  1:50 [Qemu-devel] [PATCH] implement strnlen for systems that need it John Arbuckle
@ 2017-10-20  9:25 ` David Gibson
  2017-10-20  9:38 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2017-10-20  9:25 UTC (permalink / raw)
  To: John Arbuckle; +Cc: qemu-ppc, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 3867 bytes --]

On Thu, Oct 19, 2017 at 09:50:05PM -0400, John Arbuckle wrote:
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

I preferred the idea of just putting it inline into libfdt_env.h.
They're both ugly, but that one's small and ugly; the approach here
seems overkill.

Also, patch submissions for dtc and libfdt should go to
<devicetree-compiler@vger.kernel.org>

> ---
>  Makefile.dtc           |  3 ++-
>  libfdt/Makefile.libfdt |  2 +-
>  libfdt/libfdt_env.h    | 12 ++++++++++++
>  libfdt/strnlen.h       | 14 ++++++++++++++
>  strnlen.c              | 25 +++++++++++++++++++++++++
>  5 files changed, 54 insertions(+), 2 deletions(-)
>  create mode 100644 libfdt/strnlen.h
>  create mode 100644 strnlen.c
> 
> diff --git a/Makefile.dtc b/Makefile.dtc
> index bece49b..14eaa4e 100644
> --- a/Makefile.dtc
> +++ b/Makefile.dtc
> @@ -12,7 +12,8 @@ DTC_SRCS = \
>  	livetree.c \
>  	srcpos.c \
>  	treesource.c \
> -	util.c
> +	util.c \
> +    strnlen.c
>  
>  DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
>  DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
> diff --git a/libfdt/Makefile.libfdt b/libfdt/Makefile.libfdt
> index 098b3f3..b20a85b 100644
> --- a/libfdt/Makefile.libfdt
> +++ b/libfdt/Makefile.libfdt
> @@ -7,5 +7,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
>  LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
>  LIBFDT_VERSION = version.lds
>  LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
> -	fdt_addresses.c fdt_overlay.c
> +	fdt_addresses.c fdt_overlay.c strnlen.c
>  LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
> diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h
> index 952056c..a25a615 100644
> --- a/libfdt/libfdt_env.h
> +++ b/libfdt/libfdt_env.h
> @@ -109,4 +109,16 @@ static inline fdt64_t cpu_to_fdt64(uint64_t x)
>  #undef CPU_TO_FDT16
>  #undef EXTRACT_BYTE
>  
> +#ifdef __APPLE__
> +#include <AvailabilityMacros.h>
> +
> +#define MAC_OS_X_VERSION_10_7 1070
> +
> +/* strnlen() is not available on Mac OS < 10.7 */
> +# if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
> +#include "strnlen.h"
> +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) */
> +
> +#endif /* __APPLE__ */
> +
>  #endif /* _LIBFDT_ENV_H */
> diff --git a/libfdt/strnlen.h b/libfdt/strnlen.h
> new file mode 100644
> index 0000000..62a45c0
> --- /dev/null
> +++ b/libfdt/strnlen.h
> @@ -0,0 +1,14 @@
> +/*
> + * File: strnlen.h
> + * Date: 10-19-2017
> + * Description: Implements functions that may be missing on the host system
> + */
> +
> +#ifndef STRNLEN
> +#define STRNLEN
> +
> +#include <stddef.h>
> +
> +size_t strnlen(const char *string, size_t max_count);
> +
> +#endif /* STRNLEN */
> diff --git a/strnlen.c b/strnlen.c
> new file mode 100644
> index 0000000..3559c6f
> --- /dev/null
> +++ b/strnlen.c
> @@ -0,0 +1,25 @@
> +/*
> + * File: strnlen.c
> + * Date: 10-19-2017
> + * Description: Implement the strnlen() function for platforms that need it
> + */
> +
> +#include <stddef.h>
> +#include "strnlen.h"
> +
> +/* 
> + * strnlen: returns the length of a string or max_count - which ever is smallest
> + * Input 1 string: the string whose size is to be determined
> + * Input 2 max_count: the maximum value returned by this function
> + * Output: length of the string or max_count (the smallest of the two)
> + */
> +size_t strnlen(const char *string, size_t max_count)
> +{
> +    int count;
> +    for(count = 0; count < max_count; count++) {
> +        if (string[count] == '\0') {
> +            break;
> +        }
> +    }
> +    return count;
> +}

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] implement strnlen for systems that need it
  2017-10-20  1:50 [Qemu-devel] [PATCH] implement strnlen for systems that need it John Arbuckle
  2017-10-20  9:25 ` David Gibson
@ 2017-10-20  9:38 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2017-10-20  9:38 UTC (permalink / raw)
  To: John Arbuckle; +Cc: qemu-ppc, qemu-devel, david

On Thu, Oct 19, 2017 at 09:50:05PM -0400, John Arbuckle wrote:

Which repo does this patch apply to?  Please add a tag in the email
subject like "[libfdt]" to distinguish it from qemu.git patches.

> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> ---
>  Makefile.dtc           |  3 ++-
>  libfdt/Makefile.libfdt |  2 +-
>  libfdt/libfdt_env.h    | 12 ++++++++++++
>  libfdt/strnlen.h       | 14 ++++++++++++++
>  strnlen.c              | 25 +++++++++++++++++++++++++
>  5 files changed, 54 insertions(+), 2 deletions(-)
>  create mode 100644 libfdt/strnlen.h
>  create mode 100644 strnlen.c
> 
> diff --git a/Makefile.dtc b/Makefile.dtc
> index bece49b..14eaa4e 100644
> --- a/Makefile.dtc
> +++ b/Makefile.dtc
> @@ -12,7 +12,8 @@ DTC_SRCS = \
>  	livetree.c \
>  	srcpos.c \
>  	treesource.c \
> -	util.c
> +	util.c \
> +    strnlen.c
>  
>  DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
>  DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
> diff --git a/libfdt/Makefile.libfdt b/libfdt/Makefile.libfdt
> index 098b3f3..b20a85b 100644
> --- a/libfdt/Makefile.libfdt
> +++ b/libfdt/Makefile.libfdt
> @@ -7,5 +7,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
>  LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
>  LIBFDT_VERSION = version.lds
>  LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
> -	fdt_addresses.c fdt_overlay.c
> +	fdt_addresses.c fdt_overlay.c strnlen.c
>  LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
> diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h
> index 952056c..a25a615 100644
> --- a/libfdt/libfdt_env.h
> +++ b/libfdt/libfdt_env.h
> @@ -109,4 +109,16 @@ static inline fdt64_t cpu_to_fdt64(uint64_t x)
>  #undef CPU_TO_FDT16
>  #undef EXTRACT_BYTE
>  
> +#ifdef __APPLE__
> +#include <AvailabilityMacros.h>
> +
> +#define MAC_OS_X_VERSION_10_7 1070
> +
> +/* strnlen() is not available on Mac OS < 10.7 */
> +# if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
> +#include "strnlen.h"
> +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) */
> +
> +#endif /* __APPLE__ */
> +
>  #endif /* _LIBFDT_ENV_H */
> diff --git a/libfdt/strnlen.h b/libfdt/strnlen.h
> new file mode 100644
> index 0000000..62a45c0
> --- /dev/null
> +++ b/libfdt/strnlen.h
> @@ -0,0 +1,14 @@
> +/*
> + * File: strnlen.h
> + * Date: 10-19-2017
> + * Description: Implements functions that may be missing on the host system
> + */
> +
> +#ifndef STRNLEN
> +#define STRNLEN
> +
> +#include <stddef.h>
> +
> +size_t strnlen(const char *string, size_t max_count);
> +
> +#endif /* STRNLEN */
> diff --git a/strnlen.c b/strnlen.c
> new file mode 100644
> index 0000000..3559c6f
> --- /dev/null
> +++ b/strnlen.c
> @@ -0,0 +1,25 @@
> +/*
> + * File: strnlen.c
> + * Date: 10-19-2017
> + * Description: Implement the strnlen() function for platforms that need it
> + */
> +
> +#include <stddef.h>
> +#include "strnlen.h"
> +
> +/* 
> + * strnlen: returns the length of a string or max_count - which ever is smallest
> + * Input 1 string: the string whose size is to be determined
> + * Input 2 max_count: the maximum value returned by this function
> + * Output: length of the string or max_count (the smallest of the two)
> + */
> +size_t strnlen(const char *string, size_t max_count)
> +{
> +    int count;
> +    for(count = 0; count < max_count; count++) {
> +        if (string[count] == '\0') {
> +            break;
> +        }
> +    }
> +    return count;
> +}
> -- 
> 2.10.2
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-20  9:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-20  1:50 [Qemu-devel] [PATCH] implement strnlen for systems that need it John Arbuckle
2017-10-20  9:25 ` David Gibson
2017-10-20  9:38 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).