Move major, minor + makedev portability stuff out of system.h, simplify
[platform/upstream/rpm.git] / system.h
1 /**
2  * \file system.h
3  */
4
5 #ifndef H_SYSTEM
6 #define H_SYSTEM
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #include <sys/types.h>
13
14 #include <sys/stat.h>
15 #include <stdio.h>
16
17 #ifdef HAVE_SYS_PARAM_H
18 #include <sys/param.h>
19 #endif
20
21 /* <unistd.h> should be included before any preprocessor test
22    of _POSIX_VERSION.  */
23 #ifdef HAVE_UNISTD_H
24 #include <unistd.h>
25 #if !defined(__GLIBC__)
26 #ifdef __APPLE__
27 #include <crt_externs.h>
28 #define environ (*_NSGetEnviron())
29 #else
30 extern char ** environ;
31 #endif /* __APPLE__ */
32 #endif
33 #endif
34
35 #if TIME_WITH_SYS_TIME
36 # include <sys/time.h>
37 # include <time.h>
38 #else
39 # if HAVE_SYS_TIME_H
40 #  include <sys/time.h>
41 # else
42 #  include <time.h>
43 # endif
44 #endif
45
46 #ifdef HAVE_UTIME_H
47 #include <utime.h>
48 #endif
49
50 #ifdef HAVE_STRING_H
51 # if !STDC_HEADERS && HAVE_MEMORY_H
52 #  include <memory.h>
53 # endif
54 # include <string.h>
55 #else
56 # include <strings.h>
57 #endif
58
59 #if !defined(HAVE_STPCPY)
60 char * stpcpy(char * dest, const char * src);
61 #endif
62
63 #if !defined(HAVE_STPNCPY)
64 char * stpncpy(char * dest, const char * src, size_t n);
65 #endif
66
67 #include <errno.h>
68 #ifndef errno
69 extern int errno;
70 #endif
71
72 #if HAVE___SECURE_GETENV
73 #define getenv(_s)      __secure_getenv(_s)
74 #endif
75
76 #ifdef STDC_HEADERS
77 /* FIX: shrug */
78 #define getopt system_getopt
79 #include <stdlib.h>
80 #undef getopt
81 #else /* not STDC_HEADERS */
82 char *getenv (const char *name);
83 #if ! HAVE_REALPATH
84 char *realpath(const char *path, char resolved_path []);
85 #endif
86 #endif /* STDC_HEADERS */
87
88 /* XXX solaris2.5.1 has not */
89 #if !defined(EXIT_FAILURE)
90 #define EXIT_FAILURE    1
91 #endif
92
93 #ifdef HAVE_FCNTL_H
94 #include <fcntl.h>
95 #else
96 #include <sys/file.h>
97 #endif
98
99 #if !defined(SEEK_SET)
100 #define SEEK_SET 0
101 #define SEEK_CUR 1
102 #define SEEK_END 2
103 #endif
104 #if !defined(F_OK) 
105 #define F_OK 0
106 #define X_OK 1
107 #define W_OK 2
108 #define R_OK 4
109 #endif
110
111 #ifdef HAVE_DIRENT_H
112 # include <dirent.h>
113 # define NLENGTH(direct) (strlen((direct)->d_name))
114 #else /* not HAVE_DIRENT_H */
115 # define dirent direct
116 # define NLENGTH(direct) ((direct)->d_namlen)
117 # ifdef HAVE_SYS_NDIR_H
118 #  include <sys/ndir.h>
119 # endif /* HAVE_SYS_NDIR_H */
120 # ifdef HAVE_SYS_DIR_H
121 #  include <sys/dir.h>
122 # endif /* HAVE_SYS_DIR_H */
123 # ifdef HAVE_NDIR_H
124 #  include <ndir.h>
125 # endif /* HAVE_NDIR_H */
126 #endif /* HAVE_DIRENT_H */
127
128 #include <ctype.h>
129
130 #if HAVE_SYS_MMAN_H
131 #include <sys/mman.h>
132 #endif
133
134 #if HAVE_SYS_WAIT_H
135 #include <sys/wait.h>
136 #endif
137
138 #if HAVE_LIMITS_H
139 #include <limits.h>
140 #endif
141
142 #ifndef PATH_MAX
143 #ifdef _POSIX_PATH_MAX
144 #define PATH_MAX _POSIX_PATH_MAX
145 #elif defined MAXPATHLEN
146 #define PATH_MAX MAXPATHLEN
147 #else
148 #define PATH_MAX 256
149 #endif
150 #endif
151
152 #if WITH_SELINUX
153 #include <selinux/selinux.h>
154 #else
155 typedef char * security_context_t;
156
157 #define freecon(_c)
158
159 #define getfilecon(_fn, _c)     (-1)
160 #define lgetfilecon(_fn, _c)    (-1)
161 #define fgetfilecon(_fd, _c)    (-1)
162
163 #define setfilecon(_fn, _c)     (-1)
164 #define lsetfilecon(_fn, _c)    (-1)
165 #define fsetfilecon(_fd, _c)    (-1)
166
167 #define security_check_context(_c)      (0)
168
169 #define is_selinux_enabled()    (0)
170
171 #define matchpathcon_init(_fn)                  (-1)
172 #define matchpathcon_fini()                     (0)
173 #define matchpathcon(_fn, _fm, _c)              (-1)
174
175 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
176 #endif
177
178 #if WITH_CAP
179 #include <sys/capability.h>
180 #else
181 typedef void * cap_t;
182 #endif
183
184 #if WITH_ACL
185 #include <acl/libacl.h>
186 #endif
187
188 #if HAVE_MCHECK_H
189 #include <mcheck.h>
190 #endif  /* HAVE_MCHECK_H */
191
192 #include "rpmio/rpmutil.h"
193 /* compatibility macros to avoid a mass-renaming all over the codebase */
194 #define xmalloc(_size) rmalloc((_size))
195 #define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
196 #define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
197 #define xstrdup(_str) rstrdup((_str))
198 #define _free(_ptr) rfree((_ptr))
199
200 /* Retrofit glibc __progname */
201 #if defined __GLIBC__ && __GLIBC__ >= 2
202 #if __GLIBC_MINOR__ >= 1
203 #define __progname      __assert_program_name
204 #endif
205 #define setprogname(pn)
206 #else
207 #define __progname      program_name
208 #define setprogname(pn) \
209   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
210     else __progname = pn;               \
211   }
212 #endif
213 extern const char *__progname;
214
215 #if HAVE_NETDB_H
216 #include <netdb.h>
217 #endif
218
219 /* Take care of NLS matters.  */
220
221 #if HAVE_LOCALE_H
222 # include <locale.h>
223 #endif
224 #if !HAVE_SETLOCALE
225 # define setlocale(Category, Locale) /* empty */
226 #endif
227
228 #if ENABLE_NLS
229 # include <libintl.h>
230 # define _(Text) dgettext (PACKAGE, Text)
231 #else
232 # undef bindtextdomain
233 # define bindtextdomain(Domain, Directory) /* empty */
234 # undef textdomain
235 # define textdomain(Domain) /* empty */
236 # define _(Text) Text
237 # undef dgettext
238 # define dgettext(DomainName, Text) Text
239 #endif
240
241 #define N_(Text) Text
242
243 /* ============== from misc/miscfn.h */
244
245 #if !defined(USE_GNU_GLOB) 
246 #if HAVE_FNMATCH_H
247 #include <fnmatch.h>
248 #endif
249
250 #if HAVE_GLOB_H 
251 #include <glob.h>
252 #endif
253 #else
254 #include "misc/glob.h"
255 #include "misc/fnmatch.h"
256 #endif
257
258 #if ! HAVE_S_IFSOCK
259 #define S_IFSOCK (0xc000)
260 #endif
261
262 #if ! HAVE_S_ISLNK
263 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
264 #endif
265
266 #if ! HAVE_S_ISSOCK
267 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
268 #endif
269
270 #if NEED_STRINGS_H
271 #include <strings.h>
272 #endif
273
274 #if ! HAVE_SETENV
275 extern int setenv(const char *name, const char *value, int replace);
276 extern void unsetenv(const char *name);
277 #endif
278
279 #if HAVE_POLL_H
280 #include <poll.h>
281 #else
282 #if HAVE_SYS_SELECT_H
283 #include <sys/select.h>
284 #endif
285 #endif
286
287 #if ! HAVE_LCHOWN
288 #define lchown chown
289 #endif
290
291 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
292 # define GETMNTENT_ONE 0
293 # define GETMNTENT_TWO 0
294 # if HAVE_SYS_MNTCTL_H
295 #  include <sys/mntctl.h>
296 # endif
297 # if HAVE_SYS_VMOUNT_H
298 #  include <sys/vmount.h>
299 # endif
300 # if HAVE_SYS_MOUNT_H
301 #  include <sys/mount.h>
302 # endif
303 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
304 # if HAVE_MNTENT_H
305 #  include <stdio.h>
306 #  include <mntent.h>
307 #  define our_mntent struct mntent
308 #  define our_mntdir mnt_dir
309 # elif HAVE_STRUCT_MNTTAB
310 #  include <stdio.h>
311 #  include <mnttab.h>
312    struct our_mntent {
313        char * our_mntdir;
314    };
315    struct our_mntent *getmntent(FILE *filep);
316 #  define our_mntent struct our_mntent
317 # else
318 #  include <stdio.h>
319    struct our_mntent {
320        char * our_mntdir;
321    };
322    struct our_mntent *getmntent(FILE *filep);
323 #  define our_mntent struct our_mntent
324 # endif
325 # define GETMNTENT_ONE 1
326 # define GETMNTENT_TWO 0
327 #elif HAVE_SYS_MNTTAB_H
328 # include <stdio.h>
329 # include <sys/mnttab.h>
330 # define GETMNTENT_ONE 0
331 # define GETMNTENT_TWO 1
332 # define our_mntent struct mnttab
333 # define our_mntdir mnt_mountp
334 #else /* if !HAVE_MNTCTL */
335 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
336 #endif
337
338 #ifndef MOUNTED
339 #define MOUNTED "/etc/mnttab"
340 #endif
341
342 #endif  /* H_SYSTEM */