safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
wcsncpy_s.c File Reference
#include "safe_str_lib.h"
+ Include dependency graph for wcsncpy_s.c:

Functions

EXPORT errno_t wcsncpy_s (wchar_t *restrict dest, rsize_t dmax, const wchar_t *restrict src, rsize_t slen)
 The wcsncpy_s function copies the wide string pointed to by src (including the terminating null character) into the wide string pointed to by dest. More...
 

Function Documentation

◆ wcsncpy_s()

EXPORT errno_t wcsncpy_s ( wchar_t *restrict  dest,
rsize_t  dmax,
const wchar_t *restrict  src,
rsize_t  slen 
)

The wcsncpy_s function copies the wide string pointed to by src (including the terminating null character) into the wide string pointed to by dest.

With SAFECLIB_STR_NULL_SLACK defined all elements following the terminating null character (if any) written by wcsncpy_s in the array of dmax characters pointed to by dest are nulled when wcsncpy_s returns.

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.9.2.1.2 The wcsncpy_s function (p: 639) http://en.cppreference.com/w/c/string/wide/wcsncpy
  • ISO/IEC TR 24731, Programming languages, environments and system software interfaces, Extensions to the C Library, Part I: Bounds-checking interfaces
Parameters
[out]destpointer to wide string that will be replaced by src.
[in]dmaxrestricted maximum length of dest
[in]srcpointer to the wide string that will be copied to dest
[in]slenmaximum number of wide characters to copy
Precondition
Neither dest nor src shall be a null pointer.
dmax shall not be greater than RSIZE_MAX_WSTR.
dmax shall not equal zero.
If slen is either greater than or equal to dmax, then dmax should be more than wcsnlen_s(src,dmax) to avoid truncation.
Copying shall not take place between objects that overlap.
Note
C11 uses RSIZE_MAX, not RSIZE_MAX_WSTR.
Returns
If there is a runtime-constraint violation, then if dest is not a null pointer and dmax is greater than zero and not greater than RSIZE_MAX_WSTR, then wcsncpy_s nulls dest.
Return values
EOKwhen successful operation, the wide characters in src were copied into dest and the result is null terminated.
ESNULLPwhen dest or src is a NULL pointer
ESZEROLwhen dmax = 0
ESLEMAXwhen dmax > RSIZE_MAX_WSTR
ESOVRLPwhen buffers overlap
ESNOSPCwhen dest < src
See also
wcscpy_s(), strncpy_s(), wmemcpy_s(), wmemmove_s()