WCSLCPY(3C) | Standard C Library Functions | WCSLCPY(3C) |
wcslcpy
— copy a
wide-character string
Standard C Library (libc, -lc)
#include
<wchar.h>
size_t
wcslcpy
(wchar_t *restrict dst,
wchar_t *restrict src, size_t
dstlen);
The
wcslcpy
()
function is the wide-character version of
strlcpy(3C). It copies wide
characters from src to dst,
while ensuring that dst is always properly terminated
with the null wide-character (L'\0').
Characters from src are copied until either the null wide-character is found in src or dstlen - 1 wide characters have been copied, whichever comes first. In the latter case, the copy of src in dst will be truncated. If dstlen is zero, then no characters are copied.
The wcslcpy
() function always returns the
total number of wide characters in src, excluding the
terminating null wide-character.
Example 1 Checking for overflow
The following example shows how one would check if a copy using
the wcslcpy
() function would have overflowed a fixed
size buffer. Note, the use of ‘>=’ down below is required
because the wcslcpy
() function always ensures that
the buffer has a terminating null wide-character.
#include <wchar.h> #include <stdio.h> #define BUFLEN 32 wchar_t buf[BUFLEN]; ... if (wcslcpy(buf, src, BUFLEN) >= BUFLEN) { (void) fprintf(stderr, "overflow detected!"); goto out; } ...
January 5, 2025 | OmniOS |