chiark / gitweb /
udevadm: trigger - add missing attr filter to synthesized "subsystem" register events
[elogind.git] / udev / udev_sysdeps.c
1 /*
2  * Copyright (C) 2005-2008 Kay Sievers <kay.sievers@vrfy.org>
3  *
4  *      This program is free software; you can redistribute it and/or modify it
5  *      under the terms of the GNU General Public License as published by the
6  *      Free Software Foundation version 2 of the License.
7  * 
8  *      This program is distributed in the hope that it will be useful, but
9  *      WITHOUT ANY WARRANTY; without even the implied warranty of
10  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *      General Public License for more details.
12  * 
13  *      You should have received a copy of the GNU General Public License along
14  *      with this program; if not, write to the Free Software Foundation, Inc.,
15  *      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16  *
17  */
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <sys/types.h>
23
24 #ifndef HAVE_STRLCPY
25 size_t strlcpy(char *dst, const char *src, size_t size)
26 {
27         size_t bytes = 0;
28         char *q = dst;
29         const char *p = src;
30         char ch;
31
32         while ((ch = *p++)) {
33                 if (bytes+1 < size)
34                         *q++ = ch;
35                 bytes++;
36         }
37
38         /* If size == 0 there is no space for a final null... */
39         if (size)
40                 *q = '\0';
41         return bytes;
42 }
43
44 size_t strlcat(char *dst, const char *src, size_t size)
45 {
46         size_t bytes = 0;
47         char *q = dst;
48         const char *p = src;
49         char ch;
50
51         while (bytes < size && *q) {
52                 q++;
53                 bytes++;
54         }
55         if (bytes == size)
56                 return (bytes + strlen(src));
57
58         while ((ch = *p++)) {
59                 if (bytes+1 < size)
60                 *q++ = ch;
61                 bytes++;
62         }
63
64         *q = '\0';
65         return bytes;
66 }
67 #endif /* HAVE_STRLCPY */