Eliminate SEEK_FOO and [RWXF]_OK definitions from 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 #ifdef HAVE_STRING_H
36 # if !STDC_HEADERS && HAVE_MEMORY_H
37 #  include <memory.h>
38 # endif
39 # include <string.h>
40 #else
41 # include <strings.h>
42 #endif
43
44 #if !defined(HAVE_STPCPY)
45 char * stpcpy(char * dest, const char * src);
46 #endif
47
48 #if !defined(HAVE_STPNCPY)
49 char * stpncpy(char * dest, const char * src, size_t n);
50 #endif
51
52 #include <errno.h>
53 #ifndef errno
54 extern int errno;
55 #endif
56
57 #if HAVE___SECURE_GETENV
58 #define getenv(_s)      __secure_getenv(_s)
59 #endif
60
61 #ifdef STDC_HEADERS
62 /* FIX: shrug */
63 #define getopt system_getopt
64 #include <stdlib.h>
65 #undef getopt
66 #else /* not STDC_HEADERS */
67 char *getenv (const char *name);
68 #endif /* STDC_HEADERS */
69
70 /* XXX solaris2.5.1 has not */
71 #if !defined(EXIT_FAILURE)
72 #define EXIT_FAILURE    1
73 #endif
74
75 #ifdef HAVE_FCNTL_H
76 #include <fcntl.h>
77 #else
78 #include <sys/file.h>
79 #endif
80
81 #ifdef HAVE_DIRENT_H
82 # include <dirent.h>
83 # define NLENGTH(direct) (strlen((direct)->d_name))
84 #else /* not HAVE_DIRENT_H */
85 # define dirent direct
86 # define NLENGTH(direct) ((direct)->d_namlen)
87 # ifdef HAVE_SYS_NDIR_H
88 #  include <sys/ndir.h>
89 # endif /* HAVE_SYS_NDIR_H */
90 # ifdef HAVE_SYS_DIR_H
91 #  include <sys/dir.h>
92 # endif /* HAVE_SYS_DIR_H */
93 # ifdef HAVE_NDIR_H
94 #  include <ndir.h>
95 # endif /* HAVE_NDIR_H */
96 #endif /* HAVE_DIRENT_H */
97
98 #include <ctype.h>
99
100 #if HAVE_SYS_MMAN_H
101 #include <sys/mman.h>
102 #endif
103
104 #if HAVE_SYS_WAIT_H
105 #include <sys/wait.h>
106 #endif
107
108 #if HAVE_LIMITS_H
109 #include <limits.h>
110 #endif
111
112 #ifndef PATH_MAX
113 #ifdef _POSIX_PATH_MAX
114 #define PATH_MAX _POSIX_PATH_MAX
115 #elif defined MAXPATHLEN
116 #define PATH_MAX MAXPATHLEN
117 #else
118 #define PATH_MAX 256
119 #endif
120 #endif
121
122 #if WITH_SELINUX
123 #include <selinux/selinux.h>
124 #else
125 typedef char * security_context_t;
126
127 #define freecon(_c)
128
129 #define getfilecon(_fn, _c)     (-1)
130 #define lgetfilecon(_fn, _c)    (-1)
131 #define fgetfilecon(_fd, _c)    (-1)
132
133 #define setfilecon(_fn, _c)     (-1)
134 #define lsetfilecon(_fn, _c)    (-1)
135 #define fsetfilecon(_fd, _c)    (-1)
136
137 #define security_check_context(_c)      (0)
138
139 #define is_selinux_enabled()    (0)
140
141 #define matchpathcon_init(_fn)                  (-1)
142 #define matchpathcon_fini()                     (0)
143 #define matchpathcon(_fn, _fm, _c)              (-1)
144
145 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
146 #endif
147
148 #if WITH_CAP
149 #include <sys/capability.h>
150 #else
151 typedef void * cap_t;
152 #endif
153
154 #if WITH_ACL
155 #include <acl/libacl.h>
156 #endif
157
158 #if HAVE_MCHECK_H
159 #include <mcheck.h>
160 #endif  /* HAVE_MCHECK_H */
161
162 #include "rpmio/rpmutil.h"
163 /* compatibility macros to avoid a mass-renaming all over the codebase */
164 #define xmalloc(_size) rmalloc((_size))
165 #define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
166 #define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
167 #define xstrdup(_str) rstrdup((_str))
168 #define _free(_ptr) rfree((_ptr))
169
170 /* Retrofit glibc __progname */
171 #if defined __GLIBC__ && __GLIBC__ >= 2
172 #if __GLIBC_MINOR__ >= 1
173 #define __progname      __assert_program_name
174 #endif
175 #define setprogname(pn)
176 #else
177 #define __progname      program_name
178 #define setprogname(pn) \
179   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
180     else __progname = pn;               \
181   }
182 #endif
183 extern const char *__progname;
184
185 /* Take care of NLS matters.  */
186
187 #if HAVE_LOCALE_H
188 # include <locale.h>
189 #endif
190 #if !HAVE_SETLOCALE
191 # define setlocale(Category, Locale) /* empty */
192 #endif
193
194 #if ENABLE_NLS
195 # include <libintl.h>
196 # define _(Text) dgettext (PACKAGE, Text)
197 #else
198 # undef bindtextdomain
199 # define bindtextdomain(Domain, Directory) /* empty */
200 # undef textdomain
201 # define textdomain(Domain) /* empty */
202 # define _(Text) Text
203 # undef dgettext
204 # define dgettext(DomainName, Text) Text
205 #endif
206
207 #define N_(Text) Text
208
209 /* ============== from misc/miscfn.h */
210
211 #if !defined(USE_GNU_GLOB) 
212 #if HAVE_FNMATCH_H
213 #include <fnmatch.h>
214 #endif
215
216 #if HAVE_GLOB_H 
217 #include <glob.h>
218 #endif
219 #else
220 #include "misc/glob.h"
221 #include "misc/fnmatch.h"
222 #endif
223
224 #if NEED_STRINGS_H
225 #include <strings.h>
226 #endif
227
228 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
229 # define GETMNTENT_ONE 0
230 # define GETMNTENT_TWO 0
231 # if HAVE_SYS_MNTCTL_H
232 #  include <sys/mntctl.h>
233 # endif
234 # if HAVE_SYS_VMOUNT_H
235 #  include <sys/vmount.h>
236 # endif
237 # if HAVE_SYS_MOUNT_H
238 #  include <sys/mount.h>
239 # endif
240 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
241 # if HAVE_MNTENT_H
242 #  include <stdio.h>
243 #  include <mntent.h>
244 #  define our_mntent struct mntent
245 #  define our_mntdir mnt_dir
246 # elif HAVE_STRUCT_MNTTAB
247 #  include <stdio.h>
248 #  include <mnttab.h>
249    struct our_mntent {
250        char * our_mntdir;
251    };
252    struct our_mntent *getmntent(FILE *filep);
253 #  define our_mntent struct our_mntent
254 # else
255 #  include <stdio.h>
256    struct our_mntent {
257        char * our_mntdir;
258    };
259    struct our_mntent *getmntent(FILE *filep);
260 #  define our_mntent struct our_mntent
261 # endif
262 # define GETMNTENT_ONE 1
263 # define GETMNTENT_TWO 0
264 #elif HAVE_SYS_MNTTAB_H
265 # include <stdio.h>
266 # include <sys/mnttab.h>
267 # define GETMNTENT_ONE 0
268 # define GETMNTENT_TWO 1
269 # define our_mntent struct mnttab
270 # define our_mntdir mnt_mountp
271 #else /* if !HAVE_MNTCTL */
272 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
273 #endif
274
275 #ifndef MOUNTED
276 #define MOUNTED "/etc/mnttab"
277 #endif
278
279 #endif  /* H_SYSTEM */