[quagga-dev 3098] Re: strlcpy implementation correct?
boris at tagnet.ru
Sun Apr 3 04:59:04 BST 2005
Thinking this is wrong, and
dst[size] = '\0';
should be used instead. For example, if I want to copy 1 char, then
dst[size-1] will give me a "none" str.
Andrew J. Schorr wrote:
> Will this work for now? It should be optimized to avoid reading through
> the src string twice, but that's a bit more complicated...
> strlcpy(char *dst, const char *src, size_t size)
> /* N.B. This implementation is very inefficient. */
> strncpy(dst, src, size);
> /* Make sure it terminates with a NUL char. */
> if (size > 0)
> dst[size-1] = '\0';
> return strlen(src);
More information about the Quagga-dev