1 /* $Id: strlcat.c 5681 2002-08-29 04:07:50Z rra $
3 ** Replacement for a missing strlcat.
5 ** Written by Russ Allbery <rra@stanford.edu>
6 ** This work is hereby placed in the public domain by its author.
8 ** Provides the same functionality as the *BSD function strlcat, originally
9 ** developed by Todd Miller and Theo de Raadt. strlcat works similarly to
10 ** strncat, except simpler. The result is always nul-terminated even if the
11 ** source string is longer than the space remaining in the destination
12 ** string, and the total space required is returned. The third argument is
13 ** the total space available in the destination buffer, not just the amount
14 ** of space remaining.
20 /* If we're running the test suite, rename strlcat to avoid conflicts with
21 the system version. */
23 # define strlcat test_strlcat
24 size_t test_strlcat(char *, const char *, size_t);
28 strlcat(char *dst, const char *src, size_t size)
30 size_t used, length, copy;
34 if (size > 0 && used < size - 1) {
35 copy = (length >= size - used) ? size - used - 1 : length;
36 memcpy(dst + used, src, copy);
37 dst[used + copy] = '\0';