strscpy — Copy a C-string into a sized buffer
ssize_t strscpy ( | char * dest, |
const char * src, | |
size_t count) ; |
dest
Where to copy the string to
src
Where to copy the string from
count
Size of destination buffer
Copy the string, or as much of it as fits, into the dest buffer. The behavior is undefined if the string buffers overlap. The destination buffer is always NUL terminated, unless it's zero-sized.
Preferred to strlcpy
since the API doesn't require reading memory
from the src string beyond the specified “count” bytes, and since
the return value is easier to error-check than strlcpy
's.
In addition, the implementation is robust to the string changing out
from underneath it, unlike the current strlcpy
implementation.
Preferred to strncpy
since it always returns a valid string, and
doesn't unnecessarily force the tail of the destination buffer to be
zeroed. If zeroing is desired please use strscpy_pad
.