[PATCH v2 3/7] string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp].
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Mon Jan 10 13:56:35 GMT 2022
Hi Florian,
> strncmp is commonly used as a starts-with-prefix function, as in:
>
> strncmp (s, "prefix", 6)
>
> This would be the second case: stopping at NUL before the number of
> specified bytes are read.
Indeed, such usage is both common and natural. There is only one size parameter,
so you couldn't ever use strncmp on strings you didn't know the buffer size of,
making it useless. Compilers don't optimize this to memcmp eventhough the C
standard seems to allow that, so the accepted standard is that strn* functions
must stop at the first NUL character.
Cheers,
Wilco
More information about the Libc-alpha
mailing list