]>
Commit | Line | Data |
---|---|---|
82962619 | 1 | /* |
82962619 | 2 | * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> |
dbd16d26 | 3 | * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org> |
82962619 KS |
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., | |
27b77df4 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
82962619 KS |
17 | * |
18 | */ | |
1e959a4b | 19 | |
1e959a4b | 20 | #include <stdlib.h> |
82962619 | 21 | #include <stdio.h> |
1e959a4b GKH |
22 | #include <string.h> |
23 | #include <ctype.h> | |
534c853d | 24 | #include <fcntl.h> |
4c2d04bd | 25 | #include <errno.h> |
2023350e | 26 | #include <sys/types.h> |
82962619 | 27 | |
a5b9e299 | 28 | #include "udev.h" |
82962619 | 29 | |
8a4c0c32 | 30 | #ifdef __GLIBC__ |
63f61c5c KS |
31 | size_t strlcpy(char *dst, const char *src, size_t size) |
32 | { | |
33 | size_t bytes = 0; | |
34 | char *q = dst; | |
35 | const char *p = src; | |
36 | char ch; | |
37 | ||
38 | while ((ch = *p++)) { | |
8a4c0c32 | 39 | if (bytes+1 < size) |
63f61c5c KS |
40 | *q++ = ch; |
41 | bytes++; | |
42 | } | |
43 | ||
12340f41 | 44 | /* If size == 0 there is no space for a final null... */ |
4f8d44c2 KS |
45 | if (size) |
46 | *q = '\0'; | |
63f61c5c KS |
47 | return bytes; |
48 | } | |
63f61c5c | 49 | |
63f61c5c KS |
50 | size_t strlcat(char *dst, const char *src, size_t size) |
51 | { | |
52 | size_t bytes = 0; | |
53 | char *q = dst; | |
54 | const char *p = src; | |
55 | char ch; | |
56 | ||
57 | while (bytes < size && *q) { | |
58 | q++; | |
59 | bytes++; | |
60 | } | |
8a4c0c32 KS |
61 | if (bytes == size) |
62 | return (bytes + strlen(src)); | |
57e1a277 | 63 | |
63f61c5c | 64 | while ((ch = *p++)) { |
8a4c0c32 | 65 | if (bytes+1 < size) |
63f61c5c KS |
66 | *q++ = ch; |
67 | bytes++; | |
68 | } | |
69 | ||
12340f41 | 70 | *q = '\0'; |
63f61c5c KS |
71 | return bytes; |
72 | } | |
3a020a85 | 73 | #endif /* __GLIBC__ */ |