STRLCAT 3CW "24 January 2007" "mathcw-1.00"

Table of contents


NAME

strlcat - size-bounded character-string concatenation

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <string.h> (on BSD Unix systems only)

#include <mathcw.h> extern size_t strlcat (char *target, const char *source, size_t target_length);

DESCRIPTION

strlcat copies characters from source to the end of target, stopping just before the first NUL in source, or when the number of characters copied, plus the initial length of target, has reached target_length - 1. A string-terminating NUL is then written to target as long as target_length is larger than zero, and larger than the initial length of target.

Both source and target must be NUL-terminated strings.

This function is safer and more convenient than the Standard C strcat() function, which lacks target overrun detection, and its companion, strncat(), whose length argument refers to the number of characters to be copied, rather than the size of target.


RETURN VALUES

strlcat() returns the number of characters in source, plus the initial number of characters in target. If this is larger than target_length, then target is not large enough to hold the concatenation of the two strings.

The target string is NUL-terminated provided it initially had at least one byte free.


SEE ALSO

strlcpy(3CW).