* [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen @ 2017-10-18 22:31 John Arbuckle 2017-10-19 1:31 ` David Gibson 0 siblings, 1 reply; 6+ messages in thread From: John Arbuckle @ 2017-10-18 22:31 UTC (permalink / raw) To: qemu-devel, david, qemu-ppc; +Cc: John Arbuckle Implement the strnlen() function if it isn't implemented. Signed-off-by: John Arbuckle <programmingkidx@gmail.com> --- libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 3d00d2e..a7986fb 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -55,6 +55,30 @@ #include "libfdt_internal.h" +/* if the current environment does not define strnlen */ +#ifndef strnlen + +/* This eliminates the missing prototype warning */ +int strnlen(const char *string, int max_count); + +/* + * strnlen: return the length of a string or max_count + * which ever is shortest + */ + +int strnlen(const char *string, int max_count) +{ + int count; + for(count = 0; count < max_count; count++) { + if (string[count] == '\0') { + break; + } + } + return count; +} + +#endif /* strnlen */ + static int _fdt_nodename_eq(const void *fdt, int offset, const char *s, int len) { -- 2.13.5 (Apple Git-94) ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen 2017-10-18 22:31 [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen John Arbuckle @ 2017-10-19 1:31 ` David Gibson 2017-10-19 2:39 ` Programmingkid 0 siblings, 1 reply; 6+ messages in thread From: David Gibson @ 2017-10-19 1:31 UTC (permalink / raw) To: John Arbuckle; +Cc: qemu-devel, qemu-ppc [-- Attachment #1: Type: text/plain, Size: 2209 bytes --] On Wed, Oct 18, 2017 at 06:31:16PM -0400, John Arbuckle wrote: > Implement the strnlen() function if it isn't implemented. > > Signed-off-by: John Arbuckle <programmingkidx@gmail.com> Nice idea, but this won't work. > --- > libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c > index 3d00d2e..a7986fb 100644 > --- a/libfdt/fdt_ro.c > +++ b/libfdt/fdt_ro.c > @@ -55,6 +55,30 @@ > > #include "libfdt_internal.h" > > +/* if the current environment does not define strnlen */ > +#ifndef strnlen This will only trigger if strnlen is defined as a macro. The C library (or other environment) *might* do that, but there's no guarantee, whether or not it defines strnlen as a function. With extra complications if the compiler has a strnlen builtin like gcc. > + > +/* This eliminates the missing prototype warning */ > +int strnlen(const char *string, int max_count); > + > +/* > + * strnlen: return the length of a string or max_count > + * which ever is shortest > + */ > + > +int strnlen(const char *string, int max_count) Also strnlen is supposed to take and return size_t, not int. > +{ > + int count; > + for(count = 0; count < max_count; count++) { > + if (string[count] == '\0') { > + break; > + } > + } > + return count; > +} > + > +#endif /* strnlen */ > + > static int _fdt_nodename_eq(const void *fdt, int offset, > const char *s, int len) > { In any case, this sort of compatibility munging is the job of libfdt_env.h. It's purpose is to provide all the external things that libfdt needs - there's not that many of them and strnlen() is one. The included libfdt_env.h is intended for POSIXy userspace environments, which should already include strnlen() in string.h. If your environment does not provide strnlen(), you probably need your own version of libfdt_env.h, which will need to define it. -- 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] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen 2017-10-19 1:31 ` David Gibson @ 2017-10-19 2:39 ` Programmingkid 2017-10-19 4:11 ` David Gibson 0 siblings, 1 reply; 6+ messages in thread From: Programmingkid @ 2017-10-19 2:39 UTC (permalink / raw) To: David Gibson; +Cc: qemu-devel, qemu-ppc > On Oct 18, 2017, at 9:31 PM, David Gibson <david@gibson.dropbear.id.au> wrote: > > On Wed, Oct 18, 2017 at 06:31:16PM -0400, John Arbuckle wrote: >> Implement the strnlen() function if it isn't implemented. >> >> Signed-off-by: John Arbuckle <programmingkidx@gmail.com> > > Nice idea, but this won't work. > >> --- >> libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++ >> 1 file changed, 24 insertions(+) >> >> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c >> index 3d00d2e..a7986fb 100644 >> --- a/libfdt/fdt_ro.c >> +++ b/libfdt/fdt_ro.c >> @@ -55,6 +55,30 @@ >> >> #include "libfdt_internal.h" >> >> +/* if the current environment does not define strnlen */ >> +#ifndef strnlen > > This will only trigger if strnlen is defined as a macro. The C > library (or other environment) *might* do that, but there's no > guarantee, whether or not it defines strnlen as a function. With > extra complications if the compiler has a strnlen builtin like gcc. :( >> + >> +/* This eliminates the missing prototype warning */ >> +int strnlen(const char *string, int max_count); >> + >> +/* >> + * strnlen: return the length of a string or max_count >> + * which ever is shortest >> + */ >> + >> +int strnlen(const char *string, int max_count) > > Also strnlen is supposed to take and return size_t, not int. Will change this. > >> +{ >> + int count; >> + for(count = 0; count < max_count; count++) { >> + if (string[count] == '\0') { >> + break; >> + } >> + } >> + return count; >> +} >> + >> +#endif /* strnlen */ >> + >> static int _fdt_nodename_eq(const void *fdt, int offset, >> const char *s, int len) >> { > > In any case, this sort of compatibility munging is the job of > libfdt_env.h. It's purpose is to provide all the external things that > libfdt needs - there's not that many of them and strnlen() is one. > The included libfdt_env.h is intended for POSIXy userspace > environments, which should already include strnlen() in string.h. QEMU supports Mac OS 10.5 and higher. The strnlen() function might have been added to Mac OS X in version 10.7. libfdt prevents QEMU from compiling on Mac OS X because of the missing strnlen() function. This issue needs to be resolved. If libfdt_env.h is where you want a fix located, would something like this be good: #ifdef __APPLE__ #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) size_t strnlen(const char *string, int max_count) { ... // pretend this is implemented } #endif #endif ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen 2017-10-19 2:39 ` Programmingkid @ 2017-10-19 4:11 ` David Gibson 2017-10-19 9:37 ` Peter Maydell 2017-10-19 14:54 ` Programmingkid 0 siblings, 2 replies; 6+ messages in thread From: David Gibson @ 2017-10-19 4:11 UTC (permalink / raw) To: Programmingkid; +Cc: qemu-devel, qemu-ppc [-- Attachment #1: Type: text/plain, Size: 3280 bytes --] On Wed, Oct 18, 2017 at 10:39:57PM -0400, Programmingkid wrote: > > > On Oct 18, 2017, at 9:31 PM, David Gibson <david@gibson.dropbear.id.au> wrote: > > > > On Wed, Oct 18, 2017 at 06:31:16PM -0400, John Arbuckle wrote: > >> Implement the strnlen() function if it isn't implemented. > >> > >> Signed-off-by: John Arbuckle <programmingkidx@gmail.com> > > > > Nice idea, but this won't work. > > > >> --- > >> libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++ > >> 1 file changed, 24 insertions(+) > >> > >> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c > >> index 3d00d2e..a7986fb 100644 > >> --- a/libfdt/fdt_ro.c > >> +++ b/libfdt/fdt_ro.c > >> @@ -55,6 +55,30 @@ > >> > >> #include "libfdt_internal.h" > >> > >> +/* if the current environment does not define strnlen */ > >> +#ifndef strnlen > > > > This will only trigger if strnlen is defined as a macro. The C > > library (or other environment) *might* do that, but there's no > > guarantee, whether or not it defines strnlen as a function. With > > extra complications if the compiler has a strnlen builtin like gcc. > > :( > > >> + > >> +/* This eliminates the missing prototype warning */ > >> +int strnlen(const char *string, int max_count); > >> + > >> +/* > >> + * strnlen: return the length of a string or max_count > >> + * which ever is shortest > >> + */ > >> + > >> +int strnlen(const char *string, int max_count) > > > > Also strnlen is supposed to take and return size_t, not int. > > Will change this. > > > > >> +{ > >> + int count; > >> + for(count = 0; count < max_count; count++) { > >> + if (string[count] == '\0') { > >> + break; > >> + } > >> + } > >> + return count; > >> +} > >> + > >> +#endif /* strnlen */ > >> + > >> static int _fdt_nodename_eq(const void *fdt, int offset, > >> const char *s, int len) > >> { > > > > In any case, this sort of compatibility munging is the job of > > libfdt_env.h. It's purpose is to provide all the external things that > > libfdt needs - there's not that many of them and strnlen() is one. > > The included libfdt_env.h is intended for POSIXy userspace > > environments, which should already include strnlen() in string.h. > > QEMU supports Mac OS 10.5 and higher. The strnlen() function might > have been added to Mac OS X in version 10.7. Wow. No strnlen() in MacOS until that recently, that's pretty shit. > libfdt prevents QEMU > from compiling on Mac OS X because of the missing strnlen() > function. This issue needs to be resolved. If libfdt_env.h is where > you want a fix located, would something like this be good: > > #ifdef __APPLE__ > > #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) > size_t strnlen(const char *string, int max_count) > { > ... // pretend this is implemented > } > #endif > > #endif I'm not sure I'd go as far as to call it "good" - it's kinda ugly - but it would be an acceptable solution (as long as max_count is changed to size_t as well, of course). -- 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] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen 2017-10-19 4:11 ` David Gibson @ 2017-10-19 9:37 ` Peter Maydell 2017-10-19 14:54 ` Programmingkid 1 sibling, 0 replies; 6+ messages in thread From: Peter Maydell @ 2017-10-19 9:37 UTC (permalink / raw) To: David Gibson; +Cc: Programmingkid, qemu-ppc@nongnu.org, QEMU Developers On 19 October 2017 at 05:11, David Gibson <david@gibson.dropbear.id.au> wrote: > On Wed, Oct 18, 2017 at 10:39:57PM -0400, Programmingkid wrote: >> QEMU supports Mac OS 10.5 and higher. The strnlen() function might >> have been added to Mac OS X in version 10.7. > > Wow. No strnlen() in MacOS until that recently, that's pretty shit. It's pretty poor, but the 10.7 release date was 2011, five years ago now, and it's been out of security-fix support for 2 or 3 years. thanks -- PMM ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen 2017-10-19 4:11 ` David Gibson 2017-10-19 9:37 ` Peter Maydell @ 2017-10-19 14:54 ` Programmingkid 1 sibling, 0 replies; 6+ messages in thread From: Programmingkid @ 2017-10-19 14:54 UTC (permalink / raw) To: David Gibson; +Cc: qemu-devel, qemu-ppc > On Oct 19, 2017, at 12:11 AM, David Gibson <david@gibson.dropbear.id.au> wrote: > > On Wed, Oct 18, 2017 at 10:39:57PM -0400, Programmingkid wrote: >> >>> On Oct 18, 2017, at 9:31 PM, David Gibson <david@gibson.dropbear.id.au> wrote: >>> >>> On Wed, Oct 18, 2017 at 06:31:16PM -0400, John Arbuckle wrote: >>>> Implement the strnlen() function if it isn't implemented. >>>> >>>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com> >>> >>> Nice idea, but this won't work. >>> >>>> --- >>>> libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++ >>>> 1 file changed, 24 insertions(+) >>>> >>>> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c >>>> index 3d00d2e..a7986fb 100644 >>>> --- a/libfdt/fdt_ro.c >>>> +++ b/libfdt/fdt_ro.c >>>> @@ -55,6 +55,30 @@ >>>> >>>> #include "libfdt_internal.h" >>>> >>>> +/* if the current environment does not define strnlen */ >>>> +#ifndef strnlen >>> >>> This will only trigger if strnlen is defined as a macro. The C >>> library (or other environment) *might* do that, but there's no >>> guarantee, whether or not it defines strnlen as a function. With >>> extra complications if the compiler has a strnlen builtin like gcc. >> >> :( >> >>>> + >>>> +/* This eliminates the missing prototype warning */ >>>> +int strnlen(const char *string, int max_count); >>>> + >>>> +/* >>>> + * strnlen: return the length of a string or max_count >>>> + * which ever is shortest >>>> + */ >>>> + >>>> +int strnlen(const char *string, int max_count) >>> >>> Also strnlen is supposed to take and return size_t, not int. >> >> Will change this. >> >>> >>>> +{ >>>> + int count; >>>> + for(count = 0; count < max_count; count++) { >>>> + if (string[count] == '\0') { >>>> + break; >>>> + } >>>> + } >>>> + return count; >>>> +} >>>> + >>>> +#endif /* strnlen */ >>>> + >>>> static int _fdt_nodename_eq(const void *fdt, int offset, >>>> const char *s, int len) >>>> { >>> >>> In any case, this sort of compatibility munging is the job of >>> libfdt_env.h. It's purpose is to provide all the external things that >>> libfdt needs - there's not that many of them and strnlen() is one. >>> The included libfdt_env.h is intended for POSIXy userspace >>> environments, which should already include strnlen() in string.h. >> >> QEMU supports Mac OS 10.5 and higher. The strnlen() function might >> have been added to Mac OS X in version 10.7. > > Wow. No strnlen() in MacOS until that recently, that's pretty shit. > >> libfdt prevents QEMU >> from compiling on Mac OS X because of the missing strnlen() >> function. This issue needs to be resolved. If libfdt_env.h is where >> you want a fix located, would something like this be good: > >> >> #ifdef __APPLE__ >> >> #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) >> size_t strnlen(const char *string, int max_count) >> { >> ... // pretend this is implemented >> } >> #endif >> >> #endif > > I'm not sure I'd go as far as to call it "good" - it's kinda ugly - > but it would be an acceptable solution (as long as max_count is > changed to size_t as well, of course). Yes, you are right. It is an eye sore. Libfdt is part of the Device Tree Compiler toolchain. This toolchain is something that can exist independently of QEMU. Someone could download the Device Tree Compiler toolchain and try to build it on Mac OS 10.5. This project doesn't have a configuration script but it does have a makefile. What I am thinking is add a target to the makefile that adds the strnlen() function to the toolchain if the user is building on anything less than Mac OS 10.7. The Makefile.libfdt file in the libfdt folder looks like a good place to put this code. This might be better looking. Thoughts? ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-10-19 14:54 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-10-18 22:31 [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen John Arbuckle 2017-10-19 1:31 ` David Gibson 2017-10-19 2:39 ` Programmingkid 2017-10-19 4:11 ` David Gibson 2017-10-19 9:37 ` Peter Maydell 2017-10-19 14:54 ` Programmingkid
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).