chiark / gitweb /
be97e57b1faca3c0de796ac0bfc106521167c334
[elogind.git] / udev_sysdeps.h
1 /*
2  * wrapping of libc features and kernel interfaces
3  *
4  * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
5  *
6  *      This program is free software; you can redistribute it and/or modify it
7  *      under the terms of the GNU General Public License as published by the
8  *      Free Software Foundation version 2 of the License.
9  * 
10  *      This program is distributed in the hope that it will be useful, but
11  *      WITHOUT ANY WARRANTY; without even the implied warranty of
12  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *      General Public License for more details.
14  * 
15  *      You should have received a copy of the GNU General Public License along
16  *      with this program; if not, write to the Free Software Foundation, Inc.,
17  *      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  *
19  */
20
21 #ifndef _UDEV_SYSDEPS_H_
22 #define _UDEV_SYSDEPS_H_
23
24 #include <string.h>
25 #include <unistd.h>
26 #include <stdint.h>
27
28 /* needed until Inotify! syscalls reach glibc */
29 #include <sys/syscall.h>
30 #ifndef __NR_inotify_init
31 #if defined(__i386__)
32 # define __NR_inotify_init      291
33 # define __NR_inotify_add_watch 292
34 # define __NR_inotify_rm_watch  293
35 #elif defined(__x86_64__)
36 # define __NR_inotify_init      253
37 # define __NR_inotify_add_watch 254
38 # define __NR_inotify_rm_watch  255
39 #elif defined(__powerpc__) || defined(__powerpc64__)
40 # define __NR_inotify_init      275
41 # define __NR_inotify_add_watch 276
42 # define __NR_inotify_rm_watch  277
43 #elif defined (__ia64__)
44 # define __NR_inotify_init      1277
45 # define __NR_inotify_add_watch 1278
46 # define __NR_inotify_rm_watch  1279
47 #elif defined (__s390__)
48 # define __NR_inotify_init      284
49 # define __NR_inotify_add_watch 285
50 # define __NR_inotify_rm_watch  286
51 #elif defined (__alpha__)
52 # define __NR_inotify_init      444
53 # define __NR_inotify_add_watch 445
54 # define __NR_inotify_rm_watch  446
55 #elif defined (__sparc__) || defined (__sparc64__)
56 # define __NR_inotify_init      151
57 # define __NR_inotify_add_watch 152
58 # define __NR_inotify_rm_watch  156
59 #elif defined (__arm__)
60 # define __NR_inotify_init      __NR_SYSCALL_BASE+316
61 # define __NR_inotify_add_watch __NR_SYSCALL_BASE+317
62 # define __NR_inotify_rm_watch  __NR_SYSCALL_BASE+318
63 #elif defined (__sh__)
64 # define __NR_inotify_init      290
65 # define __NR_inotify_add_watch 291
66 # define __NR_inotify_rm_watch  292
67 #elif defined (__hppa__)
68 # define __NR_inotify_init      269
69 # define __NR_inotify_add_watch 270
70 # define __NR_inotify_rm_watch  271
71 #elif defined (__mips__)
72 # include <sgidefs.h>
73 # if _MIPS_SIM == _MIPS_SIM_ABI32
74 #  define __NR_Linux             4000
75 #  define __NR_inotify_init      (__NR_Linux + 284)
76 #  define __NR_inotify_add_watch (__NR_Linux + 285)
77 #  define __NR_inotify_rm_watch  (__NR_Linux + 286)
78 # elif _MIPS_SIM == _MIPS_SIM_ABI64
79 #  define __NR_Linux             5000
80 #  define __NR_inotify_init      (__NR_Linux + 243)
81 #  define __NR_inotify_add_watch (__NR_Linux + 244)
82 #  define __NR_inotify_rm_watch  (__NR_Linux + 245)
83 # elif _MIPS_SIM == _MIPS_SIM_NABI32
84 #  define __NR_Linux             6000
85 #  define __NR_inotify_init      (__NR_Linux + 247)
86 #  define __NR_inotify_add_watch (__NR_Linux + 248)
87 #  define __NR_inotify_rm_watch  (__NR_Linux + 249)
88 # endif
89 #else
90 #warning "inotify unsupported on this architecture!"
91 #endif
92 #endif /* __NR_inotify_init */
93
94 /* dummy if we don't have the syscalls defined */
95 #ifndef __NR_inotify_init
96 static inline int inotify_init(void)
97 {
98         return -1;
99 }
100
101 static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
102 {
103         return -1;
104 }
105 #else
106 /* needed until /usr/include/sys/inotify.h is working */
107 #ifndef __GLIBC__
108 #include <sys/inotify.h>
109 #else
110 static inline int inotify_init(void)
111 {
112         return syscall(__NR_inotify_init);
113 }
114
115 static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
116 {
117         return syscall(__NR_inotify_add_watch, fd, name, mask);
118 }
119 #endif /* __GLIBC__ */
120 #endif /* __NR_inotify_init */
121
122 #ifndef IN_CREATE
123 #define IN_CREATE               0x00000100      /* Subfile was created */
124 #define IN_MOVED_FROM           0x00000040      /* File was moved from X */
125 #define IN_MOVED_TO             0x00000080      /* File was moved to Y */
126 #define IN_DELETE               0x00000200      /* Subfile was deleted */
127 #define IN_CLOSE_WRITE          0x00000008      /* Writtable file was closed */
128 #define IN_MOVE                 (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
129 #endif /* IN_CREATE */
130
131 /* needed for our signal handlers to work */
132 #undef asmlinkage
133 #ifdef __i386__
134 #define asmlinkage      __attribute__((regparm(0)))
135 #else
136 #define asmlinkage
137 #endif /* __i386__ */
138
139 /* headers are broken on some architectures */
140 #ifndef __FD_SET
141 #define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
142 #endif
143 #ifndef __FD_CLR
144 #define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
145 #endif
146 #ifndef __FD_ISSET
147 #define __FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0)
148 #endif
149 #ifndef __FD_ZERO
150 #define __FD_ZERO(set) ((void) memset ((void*) (set), 0, sizeof (fd_set)))
151 #endif
152
153 #ifndef NETLINK_KOBJECT_UEVENT
154 #define NETLINK_KOBJECT_UEVENT  15
155 #endif
156
157 #ifndef SO_RCVBUFFORCE
158 #if defined(__alpha__) || defined(__hppa__) || defined(__sparc__) || defined(__sparc_v9__)
159 #define SO_RCVBUFFORCE 0x100b
160 #else
161 #define SO_RCVBUFFORCE 33
162 #endif
163 #endif
164
165 extern size_t strlcpy(char *dst, const char *src, size_t size);
166 extern size_t strlcat(char *dst, const char *src, size_t size);
167
168 #endif