strscpy — Copy a C-string into a sized buffer
ssize_tstrscpy( | char *dest, |
| const char *src, | |
size_tcount); |
char * destWhere to copy the string to
const char * srcWhere to copy the string from
size_t countSize of destination buffer
Copy the string, or as much of it as fits, into the dest buffer. The routine returns the number of characters copied (not including the trailing NUL) or -E2BIG if the destination buffer wasn't big enough. The behavior is undefined if the string buffers overlap. The destination buffer is always NUL terminated, unless it's zero-sized.
Preferred tostrlcpy 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 thanstrlcpy's. In addition, the implementation is robust to the string changing out from underneath it, unlike the currentstrlcpy implementation.
Preferred tostrncpy since it always returns a valid string, and doesn't unnecessarily force the tail of the destination buffer to be zeroed. If the zeroing is desired, it's likely cleaner to usestrscpy with an overflow test, then justmemset the tail of the dest buffer.