Using strlcpy if target OS allows it

Joe Buck Joe.Buck@synopsys.COM
Mon Apr 18 23:05:00 GMT 2005


On Tue, Apr 19, 2005 at 12:49:15AM +0200, Marc Espie wrote:
> On Mon, Apr 18, 2005 at 01:53:52PM -0700, Joe Buck wrote:
> 
> > Clearly a local patch to use strlcpy instead of strcpy in the testsuite
> > doesn't hurt performance of the installed library, and other uses of
> > strcpy in the include headers are all equivalent to strdup: allocate
> > strlen()+1 elements and copy to it.  Is strdup a blessed routine on
> > OpenBSD?  If so, you could use it (and avoid my objection to strlcpy:
> > for every use of strcpy the buffer is exactly the right size, so using
> > strlcpy to check for overflow is wasteful).
> 
> Nope. It's a C++ FAQ, you can't use strdup.

Right, there's the malloc vs new issue and OOM handling among others.
Sorry for the bogus suggestion.

A more C++-like alternative would be to use an std::vector<char> to hold
the copy, but this would include <vector> in headers where it is not now
included.



More information about the Libstdc++ mailing list