chsvlib
chsv helper source code

◆ strCpy_s()

errno_t Chusov::String::strCpy_s ( char *restrict  pDest,
rsize_t  cchDest,
const char *restrict  pszSrc 
)
noexcept

Copies a zero-terminated source string, including a terminating null character, to a destination buffer of the specified size.

Parameters
[out]pDestis a pointer to the destination buffer where the source string is to be copied to. A size of the buffer, in bytes, is specified by the value of cchDest.
[in]cchDestis a size of the destination buffer in bytes.
[in]pszSrcis a pointer to a zero-terminated string to be copied into the buffer pointed by the value of pDest.
Returns
On success the function returns 0. If error occurs the function returns the corresponding errno code.

The function implements the behaviour of the strcpy_s function as specified in the ISO/IEC TR 24731-1 standards. This includes the following runtime constraints:

  1. Neither pDest nor pszSrc must be a NULL pointer.
  2. cchDest must neither equal zero nor be greater than RSIZE_MAX nor be less or equal to a value returned by a call

    strnLen_s(pszSrc, cchDest).

  3. The input and output buffers must not overlap.

If any of these constraints is violated the function generates a corresponding assertion and, if execution is allowed to continue, returns a corresponding errno code. If pDest is not NULL and cchDest is neither zero not greater than RSIZE_MAX, the function sets pDest[0] to '\0'.

See also
wcsCpy_s;
strCpy;
strnLen_s.