4 * $Header: /cvsroot/pgpool/pgpool-II/strlcpy.c,v 1.2.2.1 2009/08/22 04:19:49 t-ishii Exp $
6 * This file was imported from PostgreSQL source code.
7 * See below for the copyright and description.
9 * pgpool: a language independent connection pool server for PostgreSQL
10 * written by Tatsuo Ishii
12 * Portions Copyright (c) 2003-2008 PgPool Global Development Group
15 /*-------------------------------------------------------------------------
20 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
24 * $PostgreSQL: pgsql/src/port/strlcpy.c,v 1.3 2006/10/04 00:30:14 momjian Exp $
26 * This file was taken from OpenBSD and is used on platforms that don't
27 * provide strlcpy(). The OpenBSD copyright terms follow.
28 *-------------------------------------------------------------------------
31 /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
34 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
36 * Permission to use, copy, modify, and distribute this software for any
37 * purpose with or without fee is hereby granted, provided that the above
38 * copyright notice and this permission notice appear in all copies.
40 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
41 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
43 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
44 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
45 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
46 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
53 * Copy src to string dst of size siz. At most siz-1 characters
54 * will be copied. Always NUL terminates (unless siz == 0).
55 * Returns strlen(src); if retval >= siz, truncation occurred.
56 * Function creation history: http://www.gratisoft.us/todd/papers/strlcpy.html
59 strlcpy(char *dst, const char *src, size_t siz)
65 /* Copy as many bytes as will fit */
70 if ((*d++ = *s++) == '\0')
75 /* Not enough room in dst, add NUL and traverse rest of src */
79 *d = '\0'; /* NUL-terminate dst */
84 return (s - src - 1); /* count does not include NUL */