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

Functions

EXPORT errno_t strncat_s (char *restrict dest, rsize_t dmax, const char *restrict src, rsize_t slen)
 The strncat_s function appends a copy of the string pointed to by src (including the terminating null character) to the end of the string pointed to by dest. More...
 

Function Documentation

◆ strncat_s()

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

The strncat_s function appends a copy of the string pointed to by src (including the terminating null character) to the end of the string pointed to by dest.

The initial character from src overwrites the null character at the end of dest.

All elements following the terminating null character (if any) written by strncat_s in the array of dmax characters pointed to by dest take unspeciļ¬ed values when strncat_s returns. With SAFECLIB_STR_NULL_SLACK defined the rest is cleared with NULL bytes.

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.7.2.2 The strncat_s function (p: 618-620) http://en.cppreference.com/w/c/string/byte/strncat
  • 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 extended by src if dmax allows. The string is null terminated. If the resulting concatenated string is less than dmax, the remaining slack space is nulled.
[in]dmaxrestricted maximum length of the resulting dest, including the null
[in]srcpointer to the string that will be concatenaed to string dest
[in]slenmaximum characters to append
Precondition
Neither dest nor src shall be a null pointer
dmax shall not equal zero
dmax shall not be greater than RSIZE_MAX_STR
dmax shall be greater than strnlen_s(src,m).
Copying shall not takeplace 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 dmax is greater than zero and not greater than RSIZE_MAX_STR, then strncat_s sets dest[0] to the null character.
Return values
EOKsuccessful operation, all the characters from src null terminated.
ESNULLPwhen dest/src is NULL pointer
ESZEROLwhen dmax = 0
ESLEMAXwhen dmax/slen > RSIZE_MAX_STR
ESUNTERMwhen dest not terminated
ESOVRLPwhen src overlaps with dest