chiark / gitweb /
udevtest: print header that ENV{} can't work
[elogind.git] / udev_sysdeps.c
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 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <ctype.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <sys/types.h>
27
28 #include "udev.h"
29
30 #ifdef __GLIBC__
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++)) {
39                 if (bytes+1 < size)
40                         *q++ = ch;
41                 bytes++;
42         }
43
44         /* If size == 0 there is no space for a final null... */
45         if (size)
46                 *q = '\0';
47
48         return bytes;
49 }
50
51 size_t strlcat(char *dst, const char *src, size_t size)
52 {
53         size_t bytes = 0;
54         char *q = dst;
55         const char *p = src;
56         char ch;
57
58         while (bytes < size && *q) {
59                 q++;
60                 bytes++;
61         }
62         if (bytes == size)
63                 return (bytes + strlen(src));
64
65         while ((ch = *p++)) {
66                 if (bytes+1 < size)
67                 *q++ = ch;
68                 bytes++;
69         }
70
71         *q = '\0';
72         return bytes;
73 }
74 #endif /* __GLIBC__ */