[?OT?] strndup exists in FreeBSD?

Giorgos Keramidas keramida at ceid.upatras.gr
Mon Apr 14 23:50:30 UTC 2008


On Mon, 14 Apr 2008 16:27:42 -0700, "Steve Franks" <stevefranks at ieee.org> wrote:
>>  While it seems like a cool function name, what's the point of having it?
>>  If you know how much you want to copy, it's trivial to allocate a buffer
>>  large enough and strlcpy() into it.  If you don't know how much you want
>>  to copy, then strdup() is ok anyway :)
>
> Granted.  It's just one more thing to hack when porting linux code
> (which I'm getting rather tired of doing, I must admit - they seem to
> assume everyone likes to include every new api ever concieved, then
> they go off and use them...)

Ah, I see now.  I think I know the feeling...

I just saw a diff fly by at the review emails at work, which replaced
strlcpy() with strncpy() because of a similar problem, only this time
the other way around.

The libc of BSD and Solaris includes strlcpy() and strlcat(), but it's
unavailable in Linux, so we have to either "hack around" the missing
feature with strncpy() or conditionally include a BSD licensed version
of strlcpy() to our compatibility cruft.

``Portability is a huge chimera.''  Oh well :(



More information about the freebsd-questions mailing list