Str.strlcat

Portability wrapper that calls strlcat() on systems which have it, and emulates it otherwise. Appends nul-terminated src string to dest, guaranteeing nul-termination for dest. The total size of dest won't exceed dest_size.

At most dest_size - 1 characters will be copied. Unlike strncat(), dest_size is the full size of dest, not the space left over. This function does not allocate memory. It always nul-terminates (unless dest_size == 0 or there were no nul characters in the dest_size characters of dest to start with).

Caveat: this is supposedly a more secure alternative to strcat() or strncat(), but for real security g_strconcat() is harder to mess up.

struct Str
static
size_t
strlcat
(
string dest
,
string src
,
size_t destSize
)

Parameters

dest string

destination buffer, already containing one nul-terminated string

src string

source buffer

destSize size_t

length of dest buffer in bytes (not length of existing string inside dest)

Return Value

Type: size_t

size of attempted result, which is MIN (dest_size, strlen (original dest)) + strlen (src), so if retval >= dest_size, truncation occurred.