1 : /*
2 : * strlcpy.c - strlcpy() replacement
3 : * $Id: strlcpy.c 1249 2006-04-14 16:38:43Z remi $
4 : */
5 :
6 : /***********************************************************************
7 : * Copyright © 2006 Rémi Denis-Courmont. *
8 : * This program is free software; you can redistribute and/or modify *
9 : * it under the terms of the GNU General Public License as published *
10 : * by the Free Software Foundation; version 2 of the license. *
11 : * *
12 : * This program is distributed in the hope that it will be useful, *
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 : * See the GNU General Public License for more details. *
16 : * *
17 : * You should have received a copy of the GNU General Public License *
18 : * along with this program; if not, you can get it from: *
19 : * http://www.gnu.org/copyleft/gpl.html *
20 : ***********************************************************************/
21 :
22 : #ifdef HAVE_CONFIG_H
23 : # include <config.h>
24 : #endif
25 : #include <stddef.h>
26 :
27 : extern size_t strlcpy (char *tgt, const char *src, size_t bufsize)
28 33 : {
29 : size_t length;
30 :
31 133 : for (length = 1; (length < bufsize) && *src; length++)
32 100 : *tgt++ = *src++;
33 :
34 33 : if (bufsize)
35 23 : *tgt = '\0';
36 :
37 221 : while (*src++)
38 155 : length++;
39 :
40 33 : return length - 1;
41 : }
|