This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3] Implement strlcpy [BZ #178]
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Florian Weimer <fweimer at redhat dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 29 Oct 2015 14:53:11 -0700
- Subject: Re: [PATCH v3] Implement strlcpy [BZ #178]
- Authentication-results: sourceware.org; auth=none
- References: <56326B79 dot 8070804 at redhat dot com> <563294BE dot 9070105 at cs dot ucla dot edu>
On 10/29/2015 02:50 PM, Paul Eggert wrote:
We can pair this with similar phrasing under strlcpy -- something like
the following perhaps (this wording assumes strlcpy is changed to use
memmove):"Often @code{strlcpy} is not what you want, because it does
not null-terminate the destination if the destination's size is
zero,it can leave junk data behind in the destination, it can do
useless work when the source is long and the destination short, and it
may truncate the destination. Although one alternative is
@code{strncpy}, it is usually better to use dynamic memory allocation
and functions such as @code{strdup} or @code{asprintf} to construct
strings."
One more thing: we should add "it requires the source to be
null-terminated even when it is longer than the destination".