Sujet : Re: avoiding strdup()
De : 433-929-6894 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 10. Mar 2024, 18:12:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240310100715.866@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-10, Michael S <
already5chosen@yahoo.com> wrote:
On Sat, 09 Mar 2024 16:37:19 -0800
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
strdup() and strndup() are being added to the C23 standard.
>
What is justification?
strdup is required by POSIX already and thus widely implemented.
Many programmers who are not into standards already assume it's in C.
For decades, portable programs have been doing things like this:
#if HAVE_STRDUP
#define xstrdup(s) strdup(s)
#else
char *xstrdup(const char *); // own definition
#endif
What strdup() can do better, for any chosen value of better, than
strlen()+malloc()+memcpy() ?
Not take up space in every application for a common library routine.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca