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

Rob Landley rob at landley.net
Wed Nov 28 17:11:51 PST 2018


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

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...

Rob



More information about the Toybox mailing list