[Toybox] [PATCH] macOS: replace local strnstr with strcasestr.

enh enh at google.com
Wed Nov 28 17:15:39 PST 2018


On Wed, Nov 28, 2018 at 5:11 PM Rob Landley <rob at landley.net> wrote:
>
> On 11/28/18 2:30 PM, enh via Toybox wrote:
> > bionic, glibc, macOS, and musl all have strcasestr
> > (see http://man7.org/linux/man-pages/man3/strstr.3.html).
>
> Dear posix: catch up to reality. I'm sure there's a nice farm somewhere willing
> to take Jorg Schilling where he can tell everyone how much better Solaris was
> than Linux to his heart's content.
>
> > +#include <string.h>
> > +char *strcasestr(const char *haystack, const char *needle);
> > +
>
> Why are you including string.h here? That's 3 includes of it (it's in the posix
> headers in toys.h after all the portability stuff, and under __BIONIC__, and now
> here under __GLIBC__. The standard #includes are after the portability.h stuff
> so that can override them, but

iirc i was just following the style.

i did need a `#include <stdio.h>` elsewhere (i'll get round to that
patch at some point), and may just have done this by analogy.

> The reasons I hadn't done that were:
>
> 1) It's  gnu extension and didn't know where else has it. (Sounds like everybody
> though.)
>
> 2) prototypes grow "const" and "restrict" and __attribute__ and such
> semi-randomly, and if you don't get it exactly right the build breaks on a
> not-exactly-matching duplicate prototype. (You'd think "what you put on the
> stack matches" would be good enough, but no...)
>
> I've cut and pasted a couple out of the posix spec (where it's _specified_ what
> the prototype has to be), but glibc has a nasty habit of "that linux kernel
> system call was exported when you #included the header, but then they shipped a
> new version where you have to #define _gnugnuallhailstallman to get the function
> they used to freely export and I don't trust them not to break random stuff.
>
> Sigh. I'm willing to take your word that this is the right thing to do, but it
> makes me nervous...

i didn't really understand why you were so against _GNU_SOURCE.
duplicating prototypes seems worse overall (as you mention in point 2
above).

> Rob



More information about the Toybox mailing list