Subject: Re: 'Safe' string copy: strlcpy() or strncpy() ?
To: Jaromír Dolecek <>
From: Johan Danielsson <>
List: tech-userlevel
Date: 01/26/2001 23:07:37
Jarom=EDr Dolecek <> writes:

> I think that the former is less error prone, so it should probably
> be preferred (even when one doesn't care that strncpy() appends
> '\0's if 'othersrc' is shorter than sizeof(str)). On the other hand,
> strlcpy() is not part of any standard yet.

Depends what you aim at. If you want a really portable program without
configuration, you apparently can't use these functions (recent
Solaris also has them).  If not, I don't see any reason not to use
them.  They are simple enough, so it should be trivial to include in
any application.

> Separate, though related question: should old code be converted to
> use strlcpy() instead of strncpy() ?

I don't think you should put too much effort into a mass conversion
project. The problem with this is that you are quite likely to get it
wrong in many places, like the

        strcpy(foo, bar) -> strlcpy(foo, bar, sizeof(foo))=20

conversion for `char *foo'. There are places where the strncpy
behaviour is really used, even if they are not that common.