chiark / gitweb /
libudev: require LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
[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 #include "udev_sysdeps.h"
25
26 #ifndef HAVE_STRLCPY
27 size_t strlcpy(char *dst, const char *src, size_t size)
28 {
29         size_t bytes = 0;
30         char *q = dst;
31         const char *p = src;
32         char ch;
33
34         while ((ch = *p++)) {
35                 if (bytes+1 < size)
36                         *q++ = ch;
37                 bytes++;
38         }
39
40         /* If size == 0 there is no space for a final null... */
41         if (size)
42                 *q = '\0';
43         return bytes;
44 }
45
46 size_t strlcat(char *dst, const char *src, size_t size)
47 {
48         size_t bytes = 0;
49         char *q = dst;
50         const char *p = src;
51         char ch;
52
53         while (bytes < size && *q) {
54                 q++;
55                 bytes++;
56         }
57         if (bytes == size)
58                 return (bytes + strlen(src));
59
60         while ((ch = *p++)) {
61                 if (bytes+1 < size)
62                 *q++ = ch;
63                 bytes++;
64         }
65
66         *q = '\0';
67         return bytes;
68 }
69 #endif /* HAVE_STRLCPY */