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

Table of contents


NAME

strlcpy - size-bounded character-string copy

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 strlcpy (char *target, const char *source, size_t target_length);

DESCRIPTION

strlcpy copies characters from the NUL-terminated string source to target, stopping just before the first NUL, or when the number of characters copied has reached target_length - 1. It then writes a string-terminating NUL to target, as long as target_length is larger than zero.

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


RETURN VALUES

strlcpy() returns the number of characters in source. If this is larger than target_length, then target is not large enough, and has been truncated.

SEE ALSO

strlcat(3CW).