Only run test once in verbose mode.
[dabba.git] / libdabba / strlcpy.c
blob57695f63a11e7ee9a1ae97c0e167c8d58ef0d16a
1 /**
2 * \file strlcpy.c
3 * \author written by Linus Torvalds torvalds@osdl.org (c) 1991, 1992
4 * \date 1992
5 */
7 /*
8 * Copyright (C) 1991, 1992 Linus Torvalds
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
25 /* strlcpy.c taken from the Linux kernel and adapted */
27 #include <string.h>
29 /**
30 * \brief Copy a %NUL terminated string into a sized buffer
31 * \param[in] dest Where to copy the string to
32 * \param[in] src Where to copy the string from
33 * \param[in] size Size of destination buffer
35 * Compatible with *BSD: the result is always a valid
36 * NUL-terminated string that fits in the buffer (unless,
37 * of course, the buffer size is zero). It does not pad
38 * out the result like \c strncpy(3) does.
41 size_t strlcpy(char *dest, const char *src, size_t size)
43 size_t ret = strlen(src);
45 if (size) {
46 size_t len = (ret >= size) ? size - 1 : ret;
47 memcpy(dest, src, len);
48 dest[len] = '\0';
51 return ret;