strlcpy()
Defined in string.h, the strlcpy()
function copies up to
characters from the size
-1NUL
-terminated string src
to dst
.
Syntax
extern
size_t strlcpy(char
*dst
,const char
*src
, size_tsize
);
Usage
strlcpy()
takes the full size
of the buffer, not only the length, and terminates the result with NUL
as
long as size
is greater than 0. Include a byte for
the NUL
in your size
value.
The strlcpy()
function returns the total
length of the string that would have been copied
if there was unlimited space. This might or might not be equal to
the length of the string actually copied, depending
on whether there was enough space. This means that you can call strlcpy()
once
to find out how much space is required, then allocate it if you
do not have enough, and finally call strlcpy()
a
second time to do the required copy.
This function is a common BSD-derived extension to many C libraries.