carb::extras::copyStringSafe

Defined in carb/extras/StringSafe.h

inline size_t carb::extras::copyStringSafe(char *dstBuf, size_t dstBufSize, const char *srcString)

Copy a string with optional truncation.

Remark

This function copies up to dstBufSize - 1 characters from the 0-terminated string srcString to the buffer dstBuf and appends trailing \0 to the result. This function is guarantee that the result has trailing \0 as long as dstBufSize is larger than 0.

Parameters
  • dstBuf[out] pointer to a destination buffer (can be nullptr in the case if dstBufSize is zero).

  • dstBufSize[in] size in characters of the destination buffer.

  • srcString[in] pointer to a source string.

Returns

a number of copied characters to the destination buffer (not including the trailing \0).