1 /*
2 * strlcpy.c - strlcpy() replacement
3 */
4
5 /***********************************************************************
6 * Copyright © 2006 Rémi Denis-Courmont. *
7 * This program is free software; you can redistribute and/or modify *
8 * it under the terms of the GNU General Public License as published *
9 * by the Free Software Foundation; version 2 of the license, or (at *
10 * your option) any later version. *
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
strlcpy(char * tgt,const char * src,size_t bufsize)27 extern size_t strlcpy (char *tgt, const char *src, size_t bufsize)
28 {
29 size_t length;
30
31 for (length = 1; (length < bufsize) && *src; length++)
32 *tgt++ = *src++;
33
34 if (bufsize)
35 *tgt = '\0';
36
37 while (*src++)
38 length++;
39
40 return length - 1;
41 }
42