1c2dfbbduqs#include "config.h"
2c2dfbbduqs
3e00686fbapt#if HAVE_STRLCPY
4c2dfbbduqs
5c2dfbbduqsint dummy;
6c2dfbbduqs
7c2dfbbduqs#else
8c2dfbbduqs
9c2dfbbduqs/*	$OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $	*/
10c2dfbbduqs
11c2dfbbduqs/*
12c2dfbbduqs * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
13c2dfbbduqs *
14c2dfbbduqs * Permission to use, copy, modify, and distribute this software for any
15c2dfbbduqs * purpose with or without fee is hereby granted, provided that the above
16c2dfbbduqs * copyright notice and this permission notice appear in all copies.
17c2dfbbduqs *
18c2dfbbduqs * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
19c2dfbbduqs * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
20c2dfbbduqs * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
21c2dfbbduqs * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22c2dfbbduqs * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23c2dfbbduqs * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
24c2dfbbduqs * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25c2dfbbduqs */
26c2dfbbduqs
27c2dfbbduqs#include <sys/types.h>
28c2dfbbduqs#include <string.h>
29c2dfbbduqs
30c2dfbbduqs/*
31c2dfbbduqs * Copy src to string dst of size siz.  At most siz-1 characters
32c2dfbbduqs * will be copied.  Always NUL terminates (unless siz == 0).
33c2dfbbduqs * Returns strlen(src); if retval >= siz, truncation occurred.
34c2dfbbduqs */
35c2dfbbduqssize_t
36c2dfbbduqsstrlcpy(char *dst, const char *src, size_t siz)
37c2dfbbduqs{
38c2dfbbduqs	char *d = dst;
39c2dfbbduqs	const char *s = src;
40c2dfbbduqs	size_t n = siz;
41c2dfbbduqs
42c2dfbbduqs	/* Copy as many bytes as will fit */
43c2dfbbduqs	if (n != 0) {
44c2dfbbduqs		while (--n != 0) {
45c2dfbbduqs			if ((*d++ = *s++) == '\0')
46c2dfbbduqs				break;
47c2dfbbduqs		}
48c2dfbbduqs	}
49c2dfbbduqs
50c2dfbbduqs	/* Not enough room in dst, add NUL and traverse rest of src */
51c2dfbbduqs	if (n == 0) {
52c2dfbbduqs		if (siz != 0)
53c2dfbbduqs			*d = '\0';		/* NUL-terminate dst */
54c2dfbbduqs		while (*s++)
55c2dfbbduqs			;
56c2dfbbduqs	}
57c2dfbbduqs
58c2dfbbduqs	return(s - src - 1);	/* count does not include NUL */
59c2dfbbduqs}
60c2dfbbduqs
61c2dfbbduqs#endif
62