2 * Replacement for a missing strlcpy.
4 * Provides the same functionality as the *BSD function strlcpy, originally
5 * developed by Todd Miller and Theo de Raadt. strlcpy works similarly to
6 * strncpy, except saner and simpler. The result is always nul-terminated
7 * even if the source string is longer than the destination string, and the
8 * total space required is returned. The destination string is not nul-filled
9 * like strncpy does, just nul-terminated.
11 * Written by Russ Allbery <rra@stanford.edu>
12 * This work is hereby placed in the public domain by its author.
16 #include <portable/system.h>
19 * If we're running the test suite, rename strlcpy to avoid conflicts with
23 # define strlcpy test_strlcpy
24 size_t test_strlcpy(char *, const char *, size_t);
28 strlcpy(char *dst, const char *src, size_t size)
34 copy = (length >= size) ? size - 1 : length;
35 memcpy(dst, src, copy);