• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3  * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
4  *
5  *	This program is free software; you can redistribute it and/or modify it
6  *	under the terms of the GNU General Public License as published by the
7  *	Free Software Foundation version 2 of the License.
8  *
9  *	This program is distributed in the hope that it will be useful, but
10  *	WITHOUT ANY WARRANTY; without even the implied warranty of
11  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *	General Public License for more details.
13  *
14  *	You should have received a copy of the GNU General Public License along
15  *	with this program; if not, write to the Free Software Foundation, Inc.,
16  *	51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #if defined(__GLIBC__) && !(defined(__UCLIBC__) && defined(__USE_BSD))
21 #if !(__GLIBC_PREREQ(2, 38))
strlcpy(char * dst,const char * src,size_t size)22 static size_t strlcpy(char *dst, const char *src, size_t size)
23 {
24 	size_t bytes = 0;
25 	char *q = dst;
26 	const char *p = src;
27 	char ch;
28 
29 	while ((ch = *p++)) {
30 		if (bytes+1 < size)
31 			*q++ = ch;
32 		bytes++;
33 	}
34 
35 	/* If size == 0 there is no space for a final null... */
36 	if (size)
37 		*q = '\0';
38 	return bytes;
39 }
40 
strlcat(char * dst,const char * src,size_t size)41 static size_t strlcat(char *dst, const char *src, size_t size)
42 {
43 	size_t bytes = 0;
44 	char *q = dst;
45 	const char *p = src;
46 	char ch;
47 
48 	while (bytes < size && *q) {
49 		q++;
50 		bytes++;
51 	}
52 	if (bytes == size)
53 		return (bytes + strlen(src));
54 
55 	while ((ch = *p++)) {
56 		if (bytes+1 < size)
57 		*q++ = ch;
58 		bytes++;
59 	}
60 
61 	*q = '\0';
62 	return bytes;
63 }
64 #endif /* !(__GLIBC_PREREQ(2, 38)) */
65 #endif /* __GLIBC__ */
66