]> git.ipfire.org Git - thirdparty/systemd.git/blob - udev_libc_wrapper.h
Makefile: fix dependency
[thirdparty/systemd.git] / udev_libc_wrapper.h
1 /*
2 * udev_libc_wrapper - wrapping of functions missing in a specific libc
3 * or not working in a statically compiled binary
4 *
5 * Copyright (C) 2005 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 #ifndef _UDEV_LIBC_WRAPPER_H_
23 #define _UDEV_LIBC_WRAPPER_H_
24
25 #include <string.h>
26 #include <unistd.h>
27 #include <stdint.h>
28
29 /* needed until Inotify! syscalls reach glibc */
30 #include <sys/syscall.h>
31 #ifndef __NR_inotify_init
32 #if defined(__i386__)
33 # define __NR_inotify_init 291
34 # define __NR_inotify_add_watch 292
35 # define __NR_inotify_rm_watch 293
36 #elif defined(__x86_64__)
37 # define __NR_inotify_init 253
38 # define __NR_inotify_add_watch 254
39 # define __NR_inotify_rm_watch 255
40 #elif defined(__powerpc__) || defined(__powerpc64__)
41 # define __NR_inotify_init 275
42 # define __NR_inotify_add_watch 276
43 # define __NR_inotify_rm_watch 277
44 #elif defined (__ia64__)
45 # define __NR_inotify_init 1277
46 # define __NR_inotify_add_watch 1278
47 # define __NR_inotify_rm_watch 1279
48 #elif defined (__s390__)
49 # define __NR_inotify_init 284
50 # define __NR_inotify_add_watch 285
51 # define __NR_inotify_rm_watch 286
52 #elif defined (__alpha__)
53 # define __NR_inotify_init 444
54 # define __NR_inotify_add_watch 445
55 # define __NR_inotify_rm_watch 446
56 #elif defined (__sparc__) || defined (__sparc64__)
57 # define __NR_inotify_init 151
58 # define __NR_inotify_add_watch 152
59 # define __NR_inotify_rm_watch 156
60 #elif defined (__arm__)
61 # define __NR_inotify_init __NR_SYSCALL_BASE+316
62 # define __NR_inotify_add_watch __NR_SYSCALL_BASE+317
63 # define __NR_inotify_rm_watch __NR_SYSCALL_BASE+318
64 #elif defined (__sh__)
65 # define __NR_inotify_init 290
66 # define __NR_inotify_add_watch 291
67 # define __NR_inotify_rm_watch 292
68 #elif defined (__hppa__)
69 # define __NR_inotify_init 269
70 # define __NR_inotify_add_watch 270
71 # define __NR_inotify_rm_watch 271
72 #elif defined (__mips__)
73 # include <sgidefs.h>
74 # if _MIPS_SIM == _MIPS_SIM_ABI32
75 # define __NR_Linux 4000
76 # define __NR_inotify_init (__NR_Linux + 284)
77 # define __NR_inotify_add_watch (__NR_Linux + 285)
78 # define __NR_inotify_rm_watch (__NR_Linux + 286)
79 # elif _MIPS_SIM == _MIPS_SIM_ABI64
80 # define __NR_Linux 5000
81 # define __NR_inotify_init (__NR_Linux + 243)
82 # define __NR_inotify_add_watch (__NR_Linux + 244)
83 # define __NR_inotify_rm_watch (__NR_Linux + 245)
84 # elif _MIPS_SIM == _MIPS_SIM_NABI32
85 # define __NR_Linux 6000
86 # define __NR_inotify_init (__NR_Linux + 247)
87 # define __NR_inotify_add_watch (__NR_Linux + 248)
88 # define __NR_inotify_rm_watch (__NR_Linux + 249)
89 # endif
90 #else
91 #warning "inotify unsupported on this architecture!"
92 #endif
93 #endif /* __NR_inotify_init */
94
95 /* dummy if we don't have the syscalls defined */
96 #ifndef __NR_inotify_init
97 static inline int inotify_init(void)
98 {
99 return -1;
100 }
101
102 static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
103 {
104 return -1;
105 }
106 #else
107 /* needed until /usr/include/sys/inotify.h is working */
108 #ifdef __KLIBC__
109 #include <sys/inotify.h>
110 #else
111 static inline int inotify_init(void)
112 {
113 return syscall(__NR_inotify_init);
114 }
115
116 static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
117 {
118 return syscall(__NR_inotify_add_watch, fd, name, mask);
119 }
120 #endif /* __KLIBC__ */
121 #endif /* __NR_inotify_init */
122
123 #ifndef IN_CREATE
124 #define IN_CREATE 0x00000100 /* Subfile was created */
125 #define IN_MOVED_FROM 0x00000040 /* File was moved from X */
126 #define IN_MOVED_TO 0x00000080 /* File was moved to Y */
127 #define IN_DELETE 0x00000200 /* Subfile was deleted */
128 #define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
129 #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
130 #endif /* IN_CREATE */
131
132 /* needed for our signal handlers to work */
133 #undef asmlinkage
134 #ifdef __i386__
135 #define asmlinkage __attribute__((regparm(0)))
136 #else
137 #define asmlinkage
138 #endif /* __i386__ */
139
140 /* headers are broken on some architectures */
141 #ifndef __FD_SET
142 #define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
143 #endif
144 #ifndef __FD_CLR
145 #define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
146 #endif
147 #ifndef __FD_ISSET
148 #define __FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0)
149 #endif
150 #ifndef __FD_ZERO
151 #define __FD_ZERO(set) ((void) memset ((void*) (set), 0, sizeof (fd_set)))
152 #endif
153
154 #ifndef NETLINK_KOBJECT_UEVENT
155 #define NETLINK_KOBJECT_UEVENT 15
156 #endif
157
158 #ifndef SO_RCVBUFFORCE
159 #if defined(__alpha__) || defined(__hppa__) || defined(__sparc__) || defined(__sparc_v9__)
160 #define SO_RCVBUFFORCE 0x100b
161 #else
162 #define SO_RCVBUFFORCE 33
163 #endif
164 #endif
165
166 extern uid_t lookup_user(const char *user);
167 extern gid_t lookup_group(const char *group);
168
169 extern size_t strlcpy(char *dst, const char *src, size_t size);
170 extern size_t strlcat(char *dst, const char *src, size_t size);
171
172 #endif /* _UDEV_LIBC_WRAPPER_H_ */