Hi Paul!

On Tue, Sep 16, 2025 at 11:39:00PM -0700, Paul Eggert wrote:
> Alejandro Colomar proposed that the C standardization committee add the
> <string.h> functions streq[1] and memeq[2] with the obvious semantics. As I
> understand it the committee said "come back when there's existing practice",
> he then approached glibc and they said "come back when it's in the standard,
> or at least try it out in Gnulib first".

:-)

> So, I tried it out in Gnulib (see attached patches) and streq and memeq seem
> like clear wins, in that Gnulib code is easier to read and maintain. So I
> propose installing the attached patches to Gnulib.

Lovely!  Thanks!

> Alejandro also proposed several similar functions such as wcseq and wmemeq,
> but as their cousins wcscmp, wmemcmp, etc. are so rarely used these other
> proposals don't seem that helpful so I left them out of the attached
> patches.

At least in shadow utils we are using strcaseeq() too.  So users might
be interested in that one too.

In shadow utils, we can't use gnulib, due to license differences, but
I suspect other projects will have similar needs.  I see there are even
some [c_]strcasecmp() calls within gnulib, so you could improve those
with [c_]strcaseeq().

I don't use wide strings, though, so I guess not providing those is
fine.

> As Gnulib already has a streq module with different meaning, I named the new
> module "stringeq"; it implements both streq and memeq in <string.h>. There
> seemed little point to having a separate module per function.

Maybe it would be good to call the module just 'string' so that we can
add more functions to it?  I have a list of other similar functions that
I'm proposing for standardization.  A few obvious ones are:

<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3612.txt>
strpfx() - string prefix (returns boolean, for compatibility with streq)
stppfx() - string prefix (returns pointer)

<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3613.txt>
strsfx() - string suffix (returns boolean, for compatibility with streq)
stpsfx() - string suffix (returns pointer)

And then there are more.  I can provide patches for those; you don't
need to do that (unless you want to).

> [1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3611.txt
> [2]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3617.txt


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature

Reply via email to