Re: [PATCH v2 1/2] libc: Make string.h POSIX.1-2024 compliant
Brian Inglis <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Organization | Systematic Software |
| Message-ID | <[email protected]> |
On 2025-11-15 20:46, John Scott wrote:
> Simon Barth wrote:
>> POSIX.1-2024 added strlcpy, strlcat, and memmem to strings.h. Previously these functions were only available as parts of BSD or GNU extensions.
>> Fix the header so that the symbol are visible for either the right extensions, or for POSIX.1-2024.
>
> This is a pedantic comment, but technically these functions do not have to be guarded behind feature test macros at all. Functions beginning with 'str' or 'mem' in <string.h> are in implementation-reserved namespace. I believe this provision goes back to C89.
> You can see it in a C17 draft at https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2310.pdf#nameddest=subsection.7.31.13
This is qualified in the WD derived from C2023 (which adds prefix "wcs"):
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3685.pdf#page=511
"7.35.18 String handling <string.h>
1 Function names that begin with str, mem, or wcs and a lowercase letter are
potentially reserved identifiers and may be added to the declarations in the
<string.h> header.
2 Suppressing the macro definitions of memchr, strchr, strpbrk, strrchr, or
strstr to access the corresponding actual function is an obsolescent feature."
> POSIX has always done the same:
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_02_02
"2.2.2 The Name Space
All identifiers in this volume of POSIX.1-2024, except environ, are defined in
at least one of the headers, as shown in XBD 14. Headers.
When [XSI] _XOPEN_SOURCE or _POSIX_C_SOURCE is defined, each header defines or
declares some identifiers, potentially conflicting with identifiers used by the
application.
The set of identifiers visible to the application consists of precisely those
identifiers from the header pages of the included headers, as well as additional
identifiers reserved for the implementation.
In addition, some headers may make visible identifiers from other headers as
indicated on the relevant header pages.
...
Implementations may add symbols to the headers shown in the following table,
provided the identifiers for those symbols either:
1. Begin with the corresponding reserved prefixes in the table, or
...
Header Prefix Suffix Complete Name
...
<string.h> str[a-z], mem[a-z], wcs[a-z]"
excludes unguarded (str|mem|wcs)[^a-z] and may be extended by any header which
is defined to, or as implemented, includes <string.h>.
> As an example, POSIX provides that Annex K's string functions need not be guarded behind the __STDC_WANT_LIB_EXT1__ feature test macro.
--
Take care. Thanks, Brian Inglis Calgary, Alberta, Canada
La perfection est atteinte Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher but when there is no more to cut
-- Antoine de Saint-Exupéry