Subject: 'Safe' string copy: strlcpy() or strncpy() ?
To: None <>
From: Jaromír Dolecek <>
List: tech-userlevel
Date: 01/26/2001 21:18:22
what is the preferred coding preference when attempting 'safe' string copy ?

Using strlcpy(), it's like:
	strlcpy(str, otherstr, sizeof(str));

or using strncpy(), it's like:
	strncpy(str, otherstr, sizeof(str));
	str[sizeof(str)-1] = '\0';

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.

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

Jaromir Dolecek <>
@@@@  Wanna a real operating system ? Go and get NetBSD, dammit!  @@@@