* [PATCH v1] string.h: Unconditionally expose C23 functions
@ 2025-07-11 13:47 Alejandro Colomar
2025-07-11 16:44 ` [musl] " A. Wilcox
0 siblings, 1 reply; 6+ messages in thread
From: Alejandro Colomar @ 2025-07-11 13:47 UTC (permalink / raw)
To: musl; +Cc: Alejandro Colomar
memccpy(3), strnlen(3), strdup(3), and strndup(3) are now specified by
ISO C, since C23.
Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
include/string.h | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/include/string.h b/include/string.h
index 83e2b946..723cfc42 100644
--- a/include/string.h
+++ b/include/string.h
@@ -26,6 +26,7 @@ extern "C" {
void *memcpy (void *__restrict, const void *__restrict, size_t);
void *memmove (void *, const void *, size_t);
+void *memccpy (void *__restrict, const void *__restrict, int, size_t);
void *memset (void *, int, size_t);
int memcmp (const void *, const void *, size_t);
void *memchr (const void *, int, size_t);
@@ -36,6 +37,9 @@ char *strncpy (char *__restrict, const char *__restrict, size_t);
char *strcat (char *__restrict, const char *__restrict);
char *strncat (char *__restrict, const char *__restrict, size_t);
+char *strdup (const char *);
+char *strndup (const char *, size_t);
+
int strcmp (const char *, const char *);
int strncmp (const char *, const char *, size_t);
@@ -52,6 +56,7 @@ char *strstr (const char *, const char *);
char *strtok (char *__restrict, const char *__restrict);
size_t strlen (const char *);
+size_t strnlen (const char *, size_t);
char *strerror (int);
@@ -66,9 +71,6 @@ char *strtok_r (char *__restrict, const char *__restrict, char **__restrict);
int strerror_r (int, char *, size_t);
char *stpcpy(char *__restrict, const char *__restrict);
char *stpncpy(char *__restrict, const char *__restrict, size_t);
-size_t strnlen (const char *, size_t);
-char *strdup (const char *);
-char *strndup (const char *, size_t);
char *strsignal(int);
char *strerror_l (int, locale_t);
int strcoll_l (const char *, const char *, locale_t);
@@ -76,11 +78,6 @@ size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
void *memmem(const void *, size_t, const void *, size_t);
#endif
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
- || defined(_BSD_SOURCE)
-void *memccpy (void *__restrict, const void *__restrict, int, size_t);
-#endif
-
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
char *strsep(char **, const char *);
size_t strlcat (char *, const char *, size_t);
--
2.50.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [musl] [PATCH v1] string.h: Unconditionally expose C23 functions
2025-07-11 13:47 [PATCH v1] string.h: Unconditionally expose C23 functions Alejandro Colomar
@ 2025-07-11 16:44 ` A. Wilcox
2025-07-11 17:04 ` Rich Felker
0 siblings, 1 reply; 6+ messages in thread
From: A. Wilcox @ 2025-07-11 16:44 UTC (permalink / raw)
To: musl
On Jul 11, 2025, at 08:47, Alejandro Colomar <alx@kernel.org> wrote:
>
> memccpy(3), strnlen(3), strdup(3), and strndup(3) are now specified by
> ISO C, since C23.
>
> Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf>
> Signed-off-by: Alejandro Colomar <alx@kernel.org>
> ---
> include/string.h | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/include/string.h b/include/string.h
> index 83e2b946..723cfc42 100644
> --- a/include/string.h
> +++ b/include/string.h
> @@ -26,6 +26,7 @@ extern "C" {
>
> void *memcpy (void *__restrict, const void *__restrict, size_t);
> void *memmove (void *, const void *, size_t);
> +void *memccpy (void *__restrict, const void *__restrict, int, size_t);
> void *memset (void *, int, size_t);
> int memcmp (const void *, const void *, size_t);
> void *memchr (const void *, int, size_t);
> @@ -36,6 +37,9 @@ char *strncpy (char *__restrict, const char *__restrict, size_t);
> char *strcat (char *__restrict, const char *__restrict);
> char *strncat (char *__restrict, const char *__restrict, size_t);
>
> +char *strdup (const char *);
> +char *strndup (const char *, size_t);
> +
> int strcmp (const char *, const char *);
> int strncmp (const char *, const char *, size_t);
>
> @@ -52,6 +56,7 @@ char *strstr (const char *, const char *);
> char *strtok (char *__restrict, const char *__restrict);
>
> size_t strlen (const char *);
> +size_t strnlen (const char *, size_t);
>
> char *strerror (int);
>
> @@ -66,9 +71,6 @@ char *strtok_r (char *__restrict, const char *__restrict, char **__restrict);
> int strerror_r (int, char *, size_t);
> char *stpcpy(char *__restrict, const char *__restrict);
> char *stpncpy(char *__restrict, const char *__restrict, size_t);
> -size_t strnlen (const char *, size_t);
> -char *strdup (const char *);
> -char *strndup (const char *, size_t);
> char *strsignal(int);
> char *strerror_l (int, locale_t);
> int strcoll_l (const char *, const char *, locale_t);
> @@ -76,11 +78,6 @@ size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
> void *memmem(const void *, size_t, const void *, size_t);
> #endif
>
> -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
> - || defined(_BSD_SOURCE)
> -void *memccpy (void *__restrict, const void *__restrict, int, size_t);
> -#endif
> -
> #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> char *strsep(char **, const char *);
> size_t strlcat (char *, const char *, size_t);
> --
> 2.50.0
These should not be unconditionally exposed because you can still build C99 or C11 code against musl.
We actually already had to patch something like this *away* (in https://cgit.adelielinux.org/musl/commit/?id=41735bdeff548ce44afe21aa21f1345047eb18e4) to ensure no namespace pollution. Please don’t make it worse. Add || __STDC_VERSION__ >= 202311L instead.
Best,
-Anna
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [musl] [PATCH v1] string.h: Unconditionally expose C23 functions
2025-07-11 16:44 ` [musl] " A. Wilcox
@ 2025-07-11 17:04 ` Rich Felker
2025-07-11 18:55 ` Thorsten Glaser
0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2025-07-11 17:04 UTC (permalink / raw)
To: A. Wilcox; +Cc: musl
On Fri, Jul 11, 2025 at 11:44:44AM -0500, A. Wilcox wrote:
> On Jul 11, 2025, at 08:47, Alejandro Colomar <alx@kernel.org> wrote:
> >
> > memccpy(3), strnlen(3), strdup(3), and strndup(3) are now specified by
> > ISO C, since C23.
> >
> > Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf>
> > Signed-off-by: Alejandro Colomar <alx@kernel.org>
> > ---
> > include/string.h | 13 +++++--------
> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/include/string.h b/include/string.h
> > index 83e2b946..723cfc42 100644
> > --- a/include/string.h
> > +++ b/include/string.h
> > @@ -26,6 +26,7 @@ extern "C" {
> >
> > void *memcpy (void *__restrict, const void *__restrict, size_t);
> > void *memmove (void *, const void *, size_t);
> > +void *memccpy (void *__restrict, const void *__restrict, int, size_t);
> > void *memset (void *, int, size_t);
> > int memcmp (const void *, const void *, size_t);
> > void *memchr (const void *, int, size_t);
> > @@ -36,6 +37,9 @@ char *strncpy (char *__restrict, const char *__restrict, size_t);
> > char *strcat (char *__restrict, const char *__restrict);
> > char *strncat (char *__restrict, const char *__restrict, size_t);
> >
> > +char *strdup (const char *);
> > +char *strndup (const char *, size_t);
> > +
> > int strcmp (const char *, const char *);
> > int strncmp (const char *, const char *, size_t);
> >
> > @@ -52,6 +56,7 @@ char *strstr (const char *, const char *);
> > char *strtok (char *__restrict, const char *__restrict);
> >
> > size_t strlen (const char *);
> > +size_t strnlen (const char *, size_t);
> >
> > char *strerror (int);
> >
> > @@ -66,9 +71,6 @@ char *strtok_r (char *__restrict, const char *__restrict, char **__restrict);
> > int strerror_r (int, char *, size_t);
> > char *stpcpy(char *__restrict, const char *__restrict);
> > char *stpncpy(char *__restrict, const char *__restrict, size_t);
> > -size_t strnlen (const char *, size_t);
> > -char *strdup (const char *);
> > -char *strndup (const char *, size_t);
> > char *strsignal(int);
> > char *strerror_l (int, locale_t);
> > int strcoll_l (const char *, const char *, locale_t);
> > @@ -76,11 +78,6 @@ size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
> > void *memmem(const void *, size_t, const void *, size_t);
> > #endif
> >
> > -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
> > - || defined(_BSD_SOURCE)
> > -void *memccpy (void *__restrict, const void *__restrict, int, size_t);
> > -#endif
> > -
> > #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> > char *strsep(char **, const char *);
> > size_t strlcat (char *, const char *, size_t);
> > --
> > 2.50.0
>
>
> These should not be unconditionally exposed because you can still
> build C99 or C11 code against musl.
>
> We actually already had to patch something like this *away* (in
> https://cgit.adelielinux.org/musl/commit/?id=41735bdeff548ce44afe21aa21f1345047eb18e4)
> to ensure no namespace pollution. Please don’t make it worse. Add ||
> __STDC_VERSION__ >= 202311L instead.
Generally we only attempt to conform strictly to latest version of the
relevant standard, not past versions. However in this case, the
namespace str* and mem* was already reserved, so I think even without
that policy, there's no reason not to expose them unconditionally
unless we're using strictness to expose non-conforming
application-side expectations.
Rich
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] string.h: Unconditionally expose C23 functions
2025-07-11 17:04 ` Rich Felker
@ 2025-07-11 18:55 ` Thorsten Glaser
2025-07-11 20:50 ` James Y Knight
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Glaser @ 2025-07-11 18:55 UTC (permalink / raw)
To: musl; +Cc: A. Wilcox
On Fri, 11 Jul 2025, Rich Felker wrote:
>However in this case, the namespace str* and mem* was already reserved,
>so I think even without that policy, there's no reason not to expose
>them unconditionally unless we're using strictness to expose
>non-conforming application-side expectations.
Given there seems to be *no* tool in existence that can take a
C codebase and check it for use of reserved identifiers, like
is + lowercase, that is, no accessible way for people to avoid
accidentally using “reserved” identifiers, I’d ask to at least
consider it a little longer given you have actual user reports
that they have to patch out things like this downstream.
bye,
//mirabilos
--
“It is inappropriate to require that a time represented as
seconds since the Epoch precisely represent the number of
seconds between the referenced time and the Epoch.”
-- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] string.h: Unconditionally expose C23 functions
2025-07-11 18:55 ` Thorsten Glaser
@ 2025-07-11 20:50 ` James Y Knight
2025-07-11 22:41 ` A. Wilcox
0 siblings, 1 reply; 6+ messages in thread
From: James Y Knight @ 2025-07-11 20:50 UTC (permalink / raw)
To: musl; +Cc: A. Wilcox
[-- Attachment #1: Type: text/plain, Size: 503 bytes --]
On Fri, Jul 11, 2025 at 2:55 PM Thorsten Glaser <tg@mirbsd.de> wrote:
> I’d ask to at least
> consider it a little longer given you have actual user reports
> that they have to patch out things like this downstream.
Do you have examples of what, concretely, was broken and required the
patch? The commit message for the change that ifdef'd away aligned_alloc,
at_quick_exit, and quick_exit provides no info about why you found it
important to patch downstream -- only that you did so.
[-- Attachment #2: Type: text/html, Size: 802 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] string.h: Unconditionally expose C23 functions
2025-07-11 20:50 ` James Y Knight
@ 2025-07-11 22:41 ` A. Wilcox
0 siblings, 0 replies; 6+ messages in thread
From: A. Wilcox @ 2025-07-11 22:41 UTC (permalink / raw)
To: James Y Knight; +Cc: musl
On Jul 11, 2025, at 15:50, James Y Knight <jyknight@google.com> wrote:
>
> On Fri, Jul 11, 2025 at 2:55 PM Thorsten Glaser <tg@mirbsd.de> wrote:
> > I’d ask to at least
> > consider it a little longer given you have actual user reports
> > that they have to patch out things like this downstream.
>
> Do you have examples of what, concretely, was broken and required the patch? The commit message for the change that ifdef'd away aligned_alloc, at_quick_exit, and quick_exit provides no info about why you found it important to patch downstream -- only that you did so.
NSS, cURL, Boost, and multiple Perl pods all define their own `quick_exit` methods or variables. Debian Code Search may find more; this is just what I have local in /usr/src.
It is also a hard-fail from PCTS (the POSIX Conformance Test Suite) for an implementation to have visible definitions in the main namespace that are not defined by the standard.
It also ensures that -std is specified properly by upstream packages. We have already reported multiple instances to upstreams of their not specifying the correct standard version in their build recipes, causing spurious failures. I can find some of these reports if you need them.
Best,
-Anna
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-11 22:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-11 13:47 [PATCH v1] string.h: Unconditionally expose C23 functions Alejandro Colomar
2025-07-11 16:44 ` [musl] " A. Wilcox
2025-07-11 17:04 ` Rich Felker
2025-07-11 18:55 ` Thorsten Glaser
2025-07-11 20:50 ` James Y Knight
2025-07-11 22:41 ` A. Wilcox
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).