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