init_sysdeps.c (1545B)
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 static size_t strlcpy(char *dst, const char *src, size_t size) 22 { 23 size_t bytes = 0; 24 char *q = dst; 25 const char *p = src; 26 char ch; 27 28 while ((ch = *p++)) { 29 if (bytes+1 < size) 30 *q++ = ch; 31 bytes++; 32 } 33 34 /* If size == 0 there is no space for a final null... */ 35 if (size) 36 *q = '\0'; 37 return bytes; 38 } 39 40 static size_t strlcat(char *dst, const char *src, size_t size) 41 { 42 size_t bytes = 0; 43 char *q = dst; 44 const char *p = src; 45 char ch; 46 47 while (bytes < size && *q) { 48 q++; 49 bytes++; 50 } 51 if (bytes == size) 52 return (bytes + strlen(src)); 53 54 while ((ch = *p++)) { 55 if (bytes+1 < size) 56 *q++ = ch; 57 bytes++; 58 } 59 60 *q = '\0'; 61 return bytes; 62 } 63 #endif /* __GLIBC__ */