[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: memccpy(3) and stpcpy(3) status in C2x (was: stpecpy(): A better str
From: |
Steffen Nurpmeso |
Subject: |
Re: memccpy(3) and stpcpy(3) status in C2x (was: stpecpy(): A better string copy function) |
Date: |
Mon, 14 Feb 2022 21:34:47 +0100 |
User-agent: |
s-nail v14.9.23-233-gc02d5a13cc |
Martin Sebor wrote in
<dcd2227a-8e53-86d5-e6a4-7f192494d5d1@gmail.com>:
|On 2/13/22 13:32, Alejandro Colomar (man-pages) wrote:
|> On 2/13/22 19:29, Alejandro Colomar (man-pages) wrote:
..
|>>> I expect/hope stpcpy to become the new norm for string copying, though
|>>> it will require overcoming much inertia and many dusty old books.
|>>>
|>>> It was introduced to POSIX in Issue 7 (2018).
|>>>
|>>> https://pubs.opengroup.org/onlinepubs/9699919799/functions/strcpy.html
|>>>
|>>> Martin Sebor is sponsoring its inclusion in C2x.
|>>>
|>>> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2352.htm
|>>>
|>>> (It may have been accepted, or not--I haven't checked the status.)
|>>
|>> No, stpcpy(3) was not accepted. memccpy(3) was instead. The problem
|>> wasn't stpcpy(3) as it seems, but stpncpy(3) about which I'll rant a bit
|>> below :).
|>
|> I forgot to link to the C2x document, which contains very interesting
|> information:
|>
|> <http://www.open-std.org/JTC1/SC22/WG14/www/docs/n2349.htm>
|>
|> TL;DR: That document considers strlcpy(3) to be "optimal", but not
|> widely supported enough, and then selects memccpy(3) as "good enough"
|> and way more widespread.
|
|I think that was also the sentiment in WG14 when the proposal was
|discussed. N2352 proposed stpcpy and stpncpy by themselves but it
|didn't gain enough support. More detail of the committee discussion
|of both proposals (and others) is in the meeting minutes:
| http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2376.pdf
I personally like my
/*! Copy \a{src} to \a{dst}, return pointer to NUL in \a{dst}.
* Returns \NIL if \a{dst} is not large enough; \a{dst} will always be
* terminated unless \a{n} was 0 on entry. */
EXPORT char *su_cs_pcopy_n(char *dst, char const *src, uz n);
But mostly i either use memcpy if possible, or
/*! Copy at most \a{n} bytes of \a{src} to \a{dst}, and return \a{dst} again.
* Returns \NIL if \a{dst} is not large enough; \a{dst} will always be
* terminated unless \a{n} was 0 on entry.
* Also see \r{su_cs_pcopy_n()}. */
EXPORT char *su_cs_copy_n(char *dst, char const *src, uz n);
They are C-only implementations yet.
--Steffen Schönbein