[Verse-dev] R5: Introducing v_strlcpy()

Camilla Berglund elmindreda at home.se
Mon Feb 21 11:56:35 CET 2005


Emil Brink wrote:

> extern char * v_strlcpy(char *dst, const char *src, size_t size);

> It currently returns the destination buffer <dst>; I'm not sure what 
> the most useful return value actually is. OpenBSD which I was very 
> inspired of (thanks to Camilla) returns the length of the non-copied 
> part of the source, which I guess is useful but takes longer to 
> compute.

Actually, the *BSD version returns the total length of the string it 
tried to create, which is equal to 'strlen(src)'.

 From strlcpy(3) on Darwin 7.8:
"The strlcpy() and strlcat() functions return the total length of the 
string they tried to create.  For strlcpy() that means the length of 
src."

This is in order to make truncation easy to detect. Simply check 
whether the return value is less than 'size'.

---
Camilla



More information about the Verse-dev mailing list