Dont bother including <sys/socket.h>, we dont use anything from there
[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 WITH_SELINUX
177 #include <selinux/selinux.h>
178 #else
179 typedef char * security_context_t;
180
181 #define freecon(_c)
182
183 #define getfilecon(_fn, _c)     (-1)
184 #define lgetfilecon(_fn, _c)    (-1)
185 #define fgetfilecon(_fd, _c)    (-1)
186
187 #define setfilecon(_fn, _c)     (-1)
188 #define lsetfilecon(_fn, _c)    (-1)
189 #define fsetfilecon(_fd, _c)    (-1)
190
191 #define security_check_context(_c)      (0)
192
193 #define is_selinux_enabled()    (0)
194
195 #define matchpathcon_init(_fn)                  (-1)
196 #define matchpathcon_fini()                     (0)
197 #define matchpathcon(_fn, _fm, _c)              (-1)
198
199 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
200 #endif
201
202 #if WITH_CAP
203 #include <sys/capability.h>
204 #else
205 typedef void * cap_t;
206 #endif
207
208 #if WITH_ACL
209 #include <acl/libacl.h>
210 #endif
211
212 #if HAVE_MCHECK_H
213 #include <mcheck.h>
214 #endif  /* HAVE_MCHECK_H */
215
216 #include "rpmio/rpmutil.h"
217 /* compatibility macros to avoid a mass-renaming all over the codebase */
218 #define xmalloc(_size) rmalloc((_size))
219 #define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
220 #define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
221 #define xstrdup(_str) rstrdup((_str))
222 #define _free(_ptr) rfree((_ptr))
223
224 /* Retrofit glibc __progname */
225 #if defined __GLIBC__ && __GLIBC__ >= 2
226 #if __GLIBC_MINOR__ >= 1
227 #define __progname      __assert_program_name
228 #endif
229 #define setprogname(pn)
230 #else
231 #define __progname      program_name
232 #define setprogname(pn) \
233   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
234     else __progname = pn;               \
235   }
236 #endif
237 extern const char *__progname;
238
239 #if HAVE_NETDB_H
240 #include <netdb.h>
241 #endif
242
243 #if HAVE_PWD_H
244 #include <pwd.h>
245 #endif
246
247 /* Take care of NLS matters.  */
248
249 #if HAVE_LOCALE_H
250 # include <locale.h>
251 #endif
252 #if !HAVE_SETLOCALE
253 # define setlocale(Category, Locale) /* empty */
254 #endif
255
256 #if ENABLE_NLS
257 # include <libintl.h>
258 # define _(Text) dgettext (PACKAGE, Text)
259 #else
260 # undef bindtextdomain
261 # define bindtextdomain(Domain, Directory) /* empty */
262 # undef textdomain
263 # define textdomain(Domain) /* empty */
264 # define _(Text) Text
265 # undef dgettext
266 # define dgettext(DomainName, Text) Text
267 #endif
268
269 #define N_(Text) Text
270
271 /* ============== from misc/miscfn.h */
272
273 #if !defined(USE_GNU_GLOB) 
274 #if HAVE_FNMATCH_H
275 #include <fnmatch.h>
276 #endif
277
278 #if HAVE_GLOB_H 
279 #include <glob.h>
280 #endif
281 #else
282 #include "misc/glob.h"
283 #include "misc/fnmatch.h"
284 #endif
285
286 #if ! HAVE_S_IFSOCK
287 #define S_IFSOCK (0xc000)
288 #endif
289
290 #if ! HAVE_S_ISLNK
291 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
292 #endif
293
294 #if ! HAVE_S_ISSOCK
295 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
296 #endif
297
298 #if NEED_STRINGS_H
299 #include <strings.h>
300 #endif
301
302 #if ! HAVE_SETENV
303 extern int setenv(const char *name, const char *value, int replace);
304 extern void unsetenv(const char *name);
305 #endif
306
307 #if HAVE_POLL_H
308 #include <poll.h>
309 #else
310 #if HAVE_SYS_SELECT_H
311 #include <sys/select.h>
312 #endif
313 #endif
314
315 #if ! HAVE_LCHOWN
316 #define lchown chown
317 #endif
318
319 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
320 # define GETMNTENT_ONE 0
321 # define GETMNTENT_TWO 0
322 # if HAVE_SYS_MNTCTL_H
323 #  include <sys/mntctl.h>
324 # endif
325 # if HAVE_SYS_VMOUNT_H
326 #  include <sys/vmount.h>
327 # endif
328 # if HAVE_SYS_MOUNT_H
329 #  include <sys/mount.h>
330 # endif
331 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
332 # if HAVE_MNTENT_H
333 #  include <stdio.h>
334 #  include <mntent.h>
335 #  define our_mntent struct mntent
336 #  define our_mntdir mnt_dir
337 # elif HAVE_STRUCT_MNTTAB
338 #  include <stdio.h>
339 #  include <mnttab.h>
340    struct our_mntent {
341        char * our_mntdir;
342    };
343    struct our_mntent *getmntent(FILE *filep);
344 #  define our_mntent struct our_mntent
345 # else
346 #  include <stdio.h>
347    struct our_mntent {
348        char * our_mntdir;
349    };
350    struct our_mntent *getmntent(FILE *filep);
351 #  define our_mntent struct our_mntent
352 # endif
353 # define GETMNTENT_ONE 1
354 # define GETMNTENT_TWO 0
355 #elif HAVE_SYS_MNTTAB_H
356 # include <stdio.h>
357 # include <sys/mnttab.h>
358 # define GETMNTENT_ONE 0
359 # define GETMNTENT_TWO 1
360 # define our_mntent struct mnttab
361 # define our_mntdir mnt_mountp
362 #else /* if !HAVE_MNTCTL */
363 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
364 #endif
365
366 #ifndef MOUNTED
367 #define MOUNTED "/etc/mnttab"
368 #endif
369
370 #endif  /* H_SYSTEM */