strscpy9
String safe^w truncate copy
Usage
#include <linux/string.h>
ssize_t strscpy(size_t dsize; char dst[restrict dsize], const char *restrict src, size_t dsize);
Library
Linux kernel
Overview
This function copies the string pointed to by src, into a string at the buffer pointed to by dst.
If the string doesn't fit in the buffer, it is truncated.
Return value
On success, the length of the new string is returned.
On error, a negative error code is returned.
Errors
-E2BIG-
The string was truncated.
Caveats
The "s" in the name of this function refers to safety, but safety is a relative term that doesn't always apply to this function. A more appropriate name for this function would reflect what it does, which is copying a string with truncation. Some projects call this function strtcpy().
This function is not provided by any libc, so user-space programmers must implement it themselves.
Releases
2 releases since Debian 9 (Stretch); the text changed 1 time.