public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* QChar and QVoid for strchr(3), memchr(3), et al.
@ 2026-02-24 14:28 Alejandro Colomar
  2026-02-24 16:56 ` Mark Harris
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Alejandro Colomar @ 2026-02-24 14:28 UTC (permalink / raw)
  To: linux-man

[-- Attachment #1: Type: text/plain, Size: 2414 bytes --]

Hi!

ISO C23 changed the specification of string search functions so that if
the const qualifier is present in the input, the APIs preserve it in the
output.
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#subsection.7.26.5>

For example, memchr(3) and strchr(3) were previously specified as

	alx@devuan:~$ stdc C11 memchr
	void *memchr(const void *s, int c, size_t n);
	alx@devuan:~$ stdc C11 strchr
	char *strchr(const char *s, int c);

They are now specified as

	QVoid *memchr(QVoid *s, int c, size_t n);
	QChar *strchr(QChar *s, int c);

The new specification is only possible through macros, and only in
calls.  Function pointers such as &memchr or &strchr, or calls that
avoid the macro, such as (memchr)(p,0) or (strchr)(s,0), do not use the
macro, and as such, still use the old function prototype.  However, the
ability to do this is declared obsolescent by both ISO C and the glibc
manual.  This means that the underlying functions might eventually be
removed from the headers.

glibc has implemented the C23 specification in glibc-2.43, in commit
glibc.git cd748a63ab1a (2025-11-20; "Implement C23 const-preserving standard library macros").

I've written a patch for musl, but it hasn't been applied yet:
<https://www.openwall.com/lists/musl/2026/02/23/1>

gnulib has recently added a new search function, strnul(3) --which we
already document in a manual page--, and didn't include an underlying
function, since it didn't make sense to add something already obsolete.
I documented the strnul(3) API as if it were a set of C++ overloads:

	char *strnul(char *s);
	const char *strnul(const char *s);

Now that I'm considering the documentation of the glibc changes, I'm
wondering what's the most appropriate way to document them.  I have
a few questions:

-  In the SYNOPSIS, do you prefer QChar/QVoid or overload style?

	QChar *strchr(QChar *s, int c);
   vs
	char *strnul(char *s);
	const char *strnul(const char *s);

-  If we document it as QChar/QVoid, I guess we should we add a
   QChar(3)/QVoid(3) manual page documenting all of the details, to
   avoid duplicating such details in each manual page.

-  How much should we document the old function?  Should we keep that as
   a historic detail in the QChar(3)/QVoid(3) page?

Any other comments?


Have a lovely day!
Alex

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-02-25 15:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 14:28 QChar and QVoid for strchr(3), memchr(3), et al Alejandro Colomar
2026-02-24 16:56 ` Mark Harris
2026-02-24 17:14 ` Paul Eggert
2026-02-24 21:31   ` Alejandro Colomar
2026-02-24 23:04     ` Paul Eggert
2026-02-24 23:05       ` Alejandro Colomar
2026-02-24 23:19         ` Paul Eggert
2026-02-24 23:34           ` Alejandro Colomar
2026-02-25  1:03             ` Mark Harris
2026-02-25  1:15               ` Alejandro Colomar
2026-02-24 18:52 ` Rene Kita
2026-02-24 21:41   ` Alejandro Colomar
2026-02-25 15:48     ` Rene Kita

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox