SYNOPSIS
#include <wchar.h>
wchar_t *wcslcat(wchar_t *dest, const wchar_t *src, size_t size);
wchar_t *wcslcpy(wchar_t *dest, const wchar_t *src, size_t size);
DESCRIPTION
The
The
The
The source and destination wide strings should not overlap, as the behavior is undefined.
PARAMETERS
- dst
-
Is the null-terminated wcsing to be modified or appended.
- src
-
Is the null-terminated wcsing to be copied.
- size
-
Nothing will be written beyond dst+size-1.
RETURN VALUES
The
Note however, that if
EXAMPLES
The following code fragment illuwcsates the simple case:
wchar_t *s, *p, buf[BUFSIZ]; ... (void)wcslcpy(buf, s, __arraycount(buf)); (void)wcslcat(buf, p, __arraycount(buf));
To detect truncation, perhaps while building a pathname, something like the following might be used:
wchar_t *dir, *file, pname[MAXPATHLEN]; ... if (wcslcpy(pname, dir, __arraycount(pname)) >= __arraycount(pname)) goto toolong; if (wcslcat(pname, file, __arraycount(pname)) >= __arraycount(pname)) goto toolong;
Since it is known how many characters were copied the first time, things can be sped up a bit by using a copy instead of an append
wchar_t *dir, *file, pname[MAXPATHLEN]; size_t n; ... n = wcslcpy(pname, dir, __arraycount(pname)); if (n >= __arraycount(pname)) goto toolong; if (wcslcpy(pname + n, file, __arraycount(pname) - n) >= __arraycount(pname) - n) goto toolong;
However, one may question the validity of such optimizations, as they defeat the whole purpose of
MULTITHREAD SAFETY LEVEL
MT-Safe.
PORTING ISSUES
None.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
PTC MKS Toolkit 10.5 Documentation Build 40.