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