chiark / gitweb /
098 release
[elogind.git] / udev_sysdeps.c
1 /*
2  * udev_sysdeps.c - wrapping of libc features and kernel defines
3  *
4  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
5  * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
6  *
7  *      This program is free software; you can redistribute it and/or modify it
8  *      under the terms of the GNU General Public License as published by the
9  *      Free Software Foundation version 2 of the License.
10  * 
11  *      This program is distributed in the hope that it will be useful, but
12  *      WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *      General Public License for more details.
15  * 
16  *      You should have received a copy of the GNU General Public License along
17  *      with this program; if not, write to the Free Software Foundation, Inc.,
18  *      675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <fcntl.h>
27 #include <errno.h>
28 #include <sys/types.h>
29
30 #include "udev.h"
31
32 #ifdef __GLIBC__
33 size_t strlcpy(char *dst, const char *src, size_t size)
34 {
35         size_t bytes = 0;
36         char *q = dst;
37         const char *p = src;
38         char ch;
39
40         while ((ch = *p++)) {
41                 if (bytes+1 < size)
42                         *q++ = ch;
43                 bytes++;
44         }
45
46         /* If size == 0 there is no space for a final null... */
47         if (size)
48                 *q = '\0';
49
50         return bytes;
51 }
52
53 size_t strlcat(char *dst, const char *src, size_t size)
54 {
55         size_t bytes = 0;
56         char *q = dst;
57         const char *p = src;
58         char ch;
59
60         while (bytes < size && *q) {
61                 q++;
62                 bytes++;
63         }
64         if (bytes == size)
65                 return (bytes + strlen(src));
66
67         while ((ch = *p++)) {
68                 if (bytes+1 < size)
69                 *q++ = ch;
70                 bytes++;
71         }
72
73         *q = '\0';
74         return bytes;
75 }
76 #endif /* __GLIBC__ */