1 /* $Id: strlcpy.c 5681 2002-08-29 04:07:50Z rra $
3 ** Replacement for a missing strlcpy.
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 strlcpy, originally
9 ** developed by Todd Miller and Theo de Raadt. strlcpy works similarly to
10 ** strncpy, except saner and simpler. The result is always nul-terminated
11 ** even if the source string is longer than the destination string, and the
12 ** total space required is returned. The destination string is not
13 ** nul-filled like strncpy does, just nul-terminated.
19 /* If we're running the test suite, rename strlcpy to avoid conflicts with
20 the system version. */
22 # define strlcpy test_strlcpy
23 size_t test_strlcpy(char *, const char *, size_t);
27 strlcpy(char *dst, const char *src, size_t size)
33 copy = (length >= size) ? size - 1 : length;
34 memcpy(dst, src, copy);