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