Defined in carb/extras/StringSafe.h

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

Copy slice of string with optional truncation.


This function copies up to min(dstBufSize - 1, maxCharacterCount) characters from the source 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.

  • 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 (can be nullptr in the case if maxCharacterCount is zero).

  • maxCharacterCount[in] maximum number of characters to be copied from the source string.


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