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

Functions

EXPORT errno_t strcpy_s (char *restrict dest, rsize_t dmax, const char *restrict src)
 The strcpy_s function copies the string pointed to by src (including the terminating null character) into the array pointed to by dest. More...
 

Function Documentation

◆ strcpy_s()

EXPORT errno_t strcpy_s ( char *restrict  dest,
rsize_t  dmax,
const char *restrict  src 
)

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

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

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.7.1.3 The strcpy_s function (p: 615-616) http://en.cppreference.com/w/c/string/byte/strcpy
  • 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 string that will be replaced by src.
[in]dmaxrestricted maximum length of dest
[in]srcpointer to the string that will be copied to dest
Precondition
Neither dest nor src shall be a null pointer.
dmax shall not be greater than RSIZE_MAX_STR.
dmax shall not equal zero.
dmax shall be greater than strnlen_s(src, dmax).
Copying shall not take place between objects that overlap.
Note
C11 uses RSIZE_MAX, not RSIZE_MAX_STR.
Returns
If there is a runtime-constraint violation, then if dest is not a null pointer and destmax is greater than zero and not greater than RSIZE_MAX_STR, then strcpy_s nulls dest.
Return values
EOKwhen successful operation, the 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_STR
ESOVRLPwhen strings overlap
ESNOSPCwhen dest < src
See also
strcat_s(), strncat_s(), strncpy_s()