[Verse-dev] R5: Introducing v_strlcpy()

Emil Brink emil at obsession.se
Mon Feb 21 15:18:47 CET 2005


On Mon, 21 Feb 2005 11:56:35 +0100
Camilla Berglund <elmindreda at home.se> wrote:

> 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'.

Um, yeah. Thanks. I think I had understood that, but then messed up
my own understanding when trying to communicate it. It happens some-
times. :)

Still, I decided on not keeping that semantics simply because I
think the vast majority of cases in Verse use a statically sized
buffer.

Regards,

/Emil


More information about the Verse-dev mailing list