[quagga-dev 3086] Re: strlcpy implementation correct?

Hasso Tepper hasso at estpak.ee
Sat Apr 2 18:01:49 BST 2005


Andrew J. Schorr wrote:
> In lib/str.c, we have:
>
> #ifndef HAVE_STRLCPY
> /*
>  * strlcpy is a safer version of strncpy(), checking the total
>  * size of the buffer
>  */
> size_t
> strlcpy(char *dst, const char *src, size_t size)
> {
>   strncpy(dst, src, size);
>
>   return (strlen(dst));
> }
> #endif
>
> Is that actually correct?  I thought strlcpy was supposed to guarantee
> termination with '\0' (unlike strncpy)?
>
> It looks like strlcat may also be incorrect...

Sure, look at toplevel comment in str.c. Replacing these have been in my 
todo list, but haven't time for it yet. I have always something more 
important todo ;). Feel free to replace these with any GPL'ed 
strlcat/stlcpy implementations. 

Btw, Linux is the only platform which will use these. All other supported 
platforms (*BSD and Solaris) have strlcpy and strlcat in libc. Many 
projects have their own implementations in their libs because of that.


-- 
Hasso Tepper
Elion Enterprises Ltd.
WAN administrator



More information about the Quagga-dev mailing list