[PATCH] Implement strlcat [BZ#178]

Florian Weimer fweimer@redhat.com
Fri Dec 4 18:01:00 GMT 2015


On 12/03/2015 07:08 PM, Zack Weinberg wrote:

>> Calling strlcpy (DST, SRC, 0) instead of the more-obvious strlen (SRC)?
>> Really? That would be bizarre. I'd like to see an example.
> 
> char *my_strdup(char *s)
> {
>     size_t bufsiz = strlcpy(0, s, 0) + 1;
>     char *buf = malloc(bufsiz);
>     if (!buf) return 0;
>     strlcpy(buf, s, bufsiz);
>     return s;
> }

The implementation I posted does not actually support that because (like
virtually all C standard functions), a null pointer is not allowed even
if the buffer size is zero.

This is incompatible with the C++ standard library, but I did not have
any luck so far with convincing people that this needs to be fixed in
the C standard.  The strlcpy/strlcat patch is not the place for this
general discussion, I think.

Florian



More information about the Libc-alpha mailing list