vg4->misc->strscpy()
Copy string with a maximal size into a buffer with a maximal size.
SYNTAX
size_t
vg4->misc->strscpy(char *dest, size_t dsize, const char *src, size_t ssize)
FUNCTION PARAMETERS
dest | Destination buffer |
dsize | Maximal bytes to copy including terminating null |
src | Source string |
ssize | Maximal bytes to copy from src, if no terminating null before |
RETURN VALUE
Returns the number of copied bytes (excluding terminating null)
DESCRIPTION
Copy string with a maximal size into a buffer with a maximal size.
Copy src with maximal size of ssize (if no terminating null before)
into dest with maximal size of dsize (including terminating null),
dest will always be null-terminated and remaining space will be filled with 0.
This function does not copy more than dsize bytes (including terminating null).
If the copying was truncated due to this limit,
then the return value is the number of bytes (excluding terminating null),
which would have been copied if enough space had been available.
Thus, a return value of dsize or more means that the copying was truncated.
EXAMPLE
char buf[128], *ptr; const char *myfile = "/home/fred/private/mysecretfile"; size_t slen; /* copy path of myfile into buf */ ptr = strrchr(myfile, '/'); slen = vg4->misc->strscpy(buf, sizeof(buf), myfile, (size_t)(ptr - myfile)); if (slen >= sizeof(buf)) { fprintf(stderr, "buf is too small\n"); }