From: Alejandro Colomar <alx@kernel.org>
To: "G. Branden Robinson" <g.branden.robinson@gmail.com>
Cc: Joseph Myers <josmyers@redhat.com>,
linux-man@vger.kernel.org, Keith Bostic <keith@bostic.com>,
Mark Harris <mark.hsj@gmail.com>,
Nevin Liber <nevin@cplusplusguy.com>,
JeanHeyd Meneide <phdofthehouse@gmail.com>,
Christopher Bazley <chris.bazley.wg14@gmail.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
Iker Pedrosa <ipedrosa@redhat.com>,
"Evgeny Grin (Karlson2k)" <k2k@drgrin.dev>,
Kees Cook <keescook@chromium.org>,
bug-gnulib@gnu.org, libc-alpha@sourceware.org
Subject: Re: [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h>)
Date: Sat, 1 Aug 2026 14:39:45 +0200 [thread overview]
Message-ID: <am3lZ6l3B4Y1fvFO@devuan> (raw)
In-Reply-To: <20260731233253.7uwgq7m7vndqf2o2@illithid>
[-- Attachment #1: Type: text/plain, Size: 5928 bytes --]
Hi Branden,
> Date: 2026-07-31 18:32:53-0500
> From: "G. Branden Robinson" <g.branden.robinson@gmail.com>
>
[...]
>
> Okay, well, <memory.h>'s out due to the above, and <mem.h> collides with
> old, non-standard Borland and Watcom compilers (which live on still in
> environments like FreeDOS[1]).
>
> So how about <stdmem.h> or <stdmemory.h> for the standard mem*
> functions?
As I said, I think it's the other way around. <memory.h> is great,
because there's no public record of it being obsolescent. It has only
been _implicitly_ obsolescent, but the fact that it has remained without
much attention make it a good candidate. Just as much as it was done
with memccpy(3) in C23, except that memccpy(3) was brought back for
bogus reasons (it's as bad as strncpy(3) for the purpose it was
standardized).
<memory.h> is already available in all systems that matter, so programs
can start using it today, as opposed to <stdmem.h>, which could only be
used relied upon around 2036 --for the early adopters--. If we didn't
have the old <memory.h> header, I'd certainly prefer <stdmem.h>, but for
these reasons, <memory.h> seems the way to go.
> > Any reasonable change there would involve a new header, say
> > <strnpad.h> for strncpy and strncat, rather than resurrecting a very
> > old one.
>
> I agree with that. As my previous email noted, I think C programmers
> apply the mem* functions differently than they do str{n,}*. I think
> it's a good idea to erect a cordon sanitaire around the ever-troublesome
> latter functions.
I strongly disagree.
And a cordon sanitaire wouldn't help. That's the approach that n2349
took, and it was bogus. It's not a matter of saying "these two
functions are bad". It's a matter of learning what each function is
good for. And all of mem*() and strn*() are good for memory handling
and nonstring handling (which can be considered a specific case of
memory handling). Thus, all of them belong in <memory.h>.
A cordon sanitaire will continue to ignore the fact that the problem is
not in the functions themselves, but in how users think of these
functions. I expect in 10 years from now, if we don't do anything,
people will notice the same problems in memccpy(3) that we now attribute
to strncpy(3).
Just look at all the garbage that people have written with memccpy(3)
after it was standardized in C23. A Debian code search will suffice to
show the brain damage. Or you can just look at n2349, the paper that
proposed it for its standardization, which already has UB in the
examples of how it can be used for copying strings. It's all just too
ironic.
Let's make it easy to understand these functions, and avoid blaming any
functions for what really is our lack of understanding.
> > > The solution of moving both mem*() and strn*() to <memory.h> and
> > > leaving just str*() in <string.h> is a consistent one, because
> > > <string.h> then remains strictly for string APIs, and <memory.h> is
> > > for the rest of byte handling.
> >
> > It's inconsistent with how people have understood C ever since it was
> > standardized.
>
> This claim is a bit hand-wavy. C has spent its entire lifetime being
> notoriously poorly understood. But especially in early days, the
> compiler would spit out something anyway. Hackers confused the
> production of a linked object file with understanding the language.
>
> C has single-handedly elevated "undefined behavior" into a field of
> academic study.
>
> > > It wouldn't be reasonable to move strn*() to <memory.h>, and then
> > > leave mem*() in <string.h>, of course.
> > >
> > > Similarly, it wouldn't be reasonable to [move] strncpy/cat() to
> > > <memory.h> and leave the rest of strn*() and all of mem*() in
> > > <string.h>.
> >
> > On the contrary, it's only the functions for null-padded fixed-width
> > buffers that are niche functions causing confusion, compared to all
> > the rest of the functions in <string.h> for which it's a very
> > well-established and well-understood location. Some others like
> > memccpy are *obscure*, but not confusing in the same way.
>
> I agree with you here, but the base+bounds nature of the mem* functions
> versus the null-terminated nature of the str[^n]* functions, warrants
> separation.
+1
> 37 years ago the C Committee seemed to feel it needed to economize on
> standard header file names, so many unrelated interfaces got piled
> together into .h files that consequently lacked coherence (in the
> Yourdon/Constantine sense).
+1
> WG14 has been moving away from that notion for decades now. A recent
> example is <stdbit.h>. Why not continue in that laudable direction?
>
> I think
>
> stdmem.h
> string.h
> stdstrn.h
>
> would sharply separate concerns and promote clearer reasoning among
> application developers.
For the reasons above, <memory.h> is better.
About the third header, I originally thought that, and in alx-0097
I wrote about adding a <nonstring.h> header. However, the more I think
about it, the more I think these are just fine in <memory.h>. The Linux
kernel for example, renamed strncpy(3) to strtomem_pad() --and as
discussed within WG14, the _pad in that name is redundant, so it could
perfectly have been called strtomem()--. This shows that these
functions are not as unrelated to <memory.h> as their current names
suggest.
This, combined with the fact that they are already available through
<memory.h>, makes me think that we should just put them in <memory.h>,
which would lead people to think about a binary distinction between
<string.h> for string-only, and <memory.h> for memory stuff that doesn't
handle strings.
Have a lovely day!
Alex
>
> Regards,
> Branden
>
> [1] https://www.freedos.org/books/cprogramming/part8/
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-08-01 12:39 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 21:18 [PATCH 0/2] alx-0097r1 - <memory.h>, the legitimate header for memcpy(3) et al Alejandro Colomar
2026-07-31 21:18 ` [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h> Alejandro Colomar
2026-07-31 21:23 ` Joseph Myers
2026-07-31 21:28 ` Alejandro Colomar
2026-07-31 21:54 ` Sam James
2026-07-31 22:18 ` Alejandro Colomar
2026-08-01 0:12 ` Alejandro Colomar
2026-08-01 14:43 ` Sam James
2026-07-31 21:51 ` on the irresponsibility of pursuing C language reform (was: [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h>) G. Branden Robinson
2026-07-31 21:59 ` on the irresponsibility of pursuing C language reform Sam James
2026-07-31 22:24 ` G. Branden Robinson
2026-07-31 23:19 ` Alejandro Colomar
2026-08-01 14:52 ` Sam James
2026-08-01 12:01 ` Alejandro Colomar
2026-08-01 12:04 ` Alejandro Colomar
2026-08-01 14:38 ` Sam James
2026-08-01 15:15 ` Alejandro Colomar
2026-08-01 16:10 ` Sam James
2026-08-01 17:09 ` Alejandro Colomar
2026-07-31 22:10 ` on the irresponsibility of pursuing C language reform (was: [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h>) Joseph Myers
2026-07-31 22:21 ` Alejandro Colomar
2026-07-31 22:28 ` [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h> G. Branden Robinson
2026-07-31 22:42 ` on the irresponsibility of pursuing C language reform (was: [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h>) Joseph Myers
2026-07-31 22:52 ` Alejandro Colomar
2026-07-31 23:11 ` Joseph Myers
2026-07-31 23:32 ` G. Branden Robinson
2026-08-01 12:39 ` Alejandro Colomar [this message]
2026-08-01 14:26 ` Christopher Bazley
2026-08-01 15:29 ` Alejandro Colomar
2026-07-31 23:45 ` on the irresponsibility of pursuing C language reform (was: " Alejandro Colomar
2026-08-01 12:39 ` Douglas McIlroy
2026-07-31 23:08 ` [PATCH 1/2] man/man3/{mem,strn}*(): SYNOPSIS, STANDARDS: Document these as provided by <memory.h> G. Branden Robinson
2026-07-31 23:28 ` Joseph Myers
2026-07-31 23:57 ` G. Branden Robinson
2026-08-01 0:06 ` Alejandro Colomar
2026-07-31 22:05 ` Alejandro Colomar
2026-07-31 22:16 ` Joseph Myers
2026-07-31 22:33 ` Alejandro Colomar
2026-07-31 23:48 ` [PATCH 1/2] man/man3/{mem, strn}*(): " Collin Funk
2026-07-31 23:52 ` Alejandro Colomar
2026-08-01 0:01 ` Alejandro Colomar
2026-07-31 21:19 ` [PATCH 2/2] man/man*/{string.3,memory.h.3head}: Move functions to a new page memory.h(3head) Alejandro Colomar
2026-07-31 21:20 ` [PATCH 0/2] alx-0097r1 - <memory.h>, the legitimate header for memcpy(3) et al Alejandro Colomar
2026-08-01 0:25 ` [PATCH v2] man/man3/mem*(): SYNOPSIS: Document non-standard mem*() functions as provided by <memory.h> Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=am3lZ6l3B4Y1fvFO@devuan \
--to=alx@kernel.org \
--cc=bug-gnulib@gnu.org \
--cc=chris.bazley.wg14@gmail.com \
--cc=g.branden.robinson@gmail.com \
--cc=ipedrosa@redhat.com \
--cc=josmyers@redhat.com \
--cc=k2k@drgrin.dev \
--cc=keescook@chromium.org \
--cc=keith@bostic.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-man@vger.kernel.org \
--cc=mark.hsj@gmail.com \
--cc=nevin@cplusplusguy.com \
--cc=phdofthehouse@gmail.com \
--cc=serge@hallyn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.