safec 3.15
Safe C Library - ISO TR24731 Bounds Checking Interface
Loading...
Searching...
No Matches
strlcat.c File Reference
#include "safe_str_lib.h"
Include dependency graph for strlcat.c:

Functions

EXPORT size_t strlcat (char *restrict dest, const char *restrict src, size_t dsize)
 strlcat appends the NUL-terminated string src to the end of the NUL-terminated string dest, but never writes more than dsize bytes in total (including the terminating NUL) and always NUL-terminates the result (unless dsize is 0 or dest is not already NUL-terminated within the first dsize bytes).

Function Documentation

◆ strlcat()

EXPORT size_t strlcat ( char *restrict dest,
const char *restrict src,
size_t dsize )

strlcat appends the NUL-terminated string src to the end of the NUL-terminated string dest, but never writes more than dsize bytes in total (including the terminating NUL) and always NUL-terminates the result (unless dsize is 0 or dest is not already NUL-terminated within the first dsize bytes).

The caller must check whether truncation occurred by comparing the return value against dsize.

This is only compiled in when the platform libc does not already provide strlcat (see configure's HAVE_STRLCAT / cmake's HAVE_STRLCAT probe).

Remarks
SPECIFIED IN
  • BSD, since 4.4BSD-Lite2, glibc 2.38+, musl, macOS
Parameters
[in,out]destNUL-terminated buffer that src is appended to
[in]srcpointer to the NUL-terminated string to append
[in]dsizetotal size of the dest buffer, in bytes
Precondition
Neither dest nor src shall be a null pointer.
dest shall be NUL-terminated within the first dsize bytes.
Returns
the total length of the string it tried to create, i.e. the initial length of dest plus the length of src. If the return value is >= dsize, the output was truncated.
See also
strlcpy(), strcat_s(), strncat_s()