lclint fiddles.
[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 #include <sys/stat.h>
14 #include <stdio.h>
15
16 #ifdef HAVE_SYS_PARAM_H
17 #include <sys/param.h>
18 #endif
19
20 /* <unistd.h> should be included before any preprocessor test
21    of _POSIX_VERSION.  */
22 #ifdef HAVE_UNISTD_H
23 #include <unistd.h>
24 #endif
25
26 #if TIME_WITH_SYS_TIME
27 # include <sys/time.h>
28 # include <time.h>
29 #else
30 # if HAVE_SYS_TIME_H
31 #  include <sys/time.h>
32 # else
33 #  include <time.h>
34 # endif
35 #endif
36
37 #if NEED_TIMEZONE
38 extern time_t timezone;
39 #endif
40
41 #ifdef  __LCLINT__
42 typedef unsigned int u_int32_t;
43 typedef unsigned short u_int16_t;
44 typedef unsigned char u_int8_t;
45 typedef int int32_t;
46 #endif
47
48 /* Since major is a function on SVR4, we can't use `ifndef major'.  */
49 #if MAJOR_IN_MKDEV
50 #include <sys/mkdev.h>
51 #define HAVE_MAJOR
52 #endif
53 #if MAJOR_IN_SYSMACROS
54 #include <sys/sysmacros.h>
55 #define HAVE_MAJOR
56 #endif
57 #ifdef major                    /* Might be defined in sys/types.h.  */
58 #define HAVE_MAJOR
59 #endif
60
61 #ifndef HAVE_MAJOR
62 #define major(dev)  (((dev) >> 8) & 0xff)
63 #define minor(dev)  ((dev) & 0xff)
64 #define makedev(maj, min)  (((maj) << 8) | (min))
65 #endif
66 #undef HAVE_MAJOR
67
68 #ifdef HAVE_UTIME_H
69 #include <utime.h>
70 #endif
71
72 /* Don't use bcopy!  Use memmove if source and destination may overlap,
73    memcpy otherwise.  */
74
75 #ifdef HAVE_STRING_H
76 # if !STDC_HEADERS && HAVE_MEMORY_H
77 #  include <memory.h>
78 # endif
79 # include <string.h>
80 #else
81 # include <strings.h>
82 char *memchr ();
83 #endif
84
85 #if !defined(HAVE_STPCPY) || defined(__LCLINT__)
86 /*@-declundef@*/
87 char * stpcpy(char * dest, const char * src)    /*@modifies *dest @*/;
88 /*@=declundef@*/
89 #endif
90
91 #if !defined(HAVE_STPNCPY) || defined(__LCLINT__)
92 /*@-declundef@*/
93 char * stpncpy(char * dest, const char * src, size_t n) /*@modifies *dest @*/;
94 /*@=declundef@*/
95 #endif
96
97 #include <errno.h>
98 #ifndef errno
99 /*@-declundef @*/
100 extern int errno;
101 /*@=declundef @*/
102 #endif
103
104 #ifdef STDC_HEADERS
105 /*@-macrounrecog -incondefs -globuse@*/ /* FIX: shrug */
106 #define getopt system_getopt
107 /*@=macrounrecog =incondefs =globuse@*/
108 /*@-skipansiheaders@*/
109 #include <stdlib.h>
110 /*@=skipansiheaders@*/
111 #undef getopt
112 #else /* not STDC_HEADERS */
113 char *getenv (const char *name);
114 #endif /* STDC_HEADERS */
115
116 /* XXX solaris2.5.1 has not */
117 #if !defined(EXIT_FAILURE)
118 #define EXIT_FAILURE    1
119 #endif
120
121 #ifdef HAVE_FCNTL_H
122 #include <fcntl.h>
123 #else
124 #include <sys/file.h>
125 #endif
126
127 #if !defined(SEEK_SET) && !defined(__LCLINT__)
128 #define SEEK_SET 0
129 #define SEEK_CUR 1
130 #define SEEK_END 2
131 #endif
132 #if !defined(F_OK) && !defined(__LCLINT__)
133 #define F_OK 0
134 #define X_OK 1
135 #define W_OK 2
136 #define R_OK 4
137 #endif
138
139 #ifdef HAVE_DIRENT_H
140 # include <dirent.h>
141 # define NLENGTH(direct) (strlen((direct)->d_name))
142 #else /* not HAVE_DIRENT_H */
143 # define dirent direct
144 # define NLENGTH(direct) ((direct)->d_namlen)
145 # ifdef HAVE_SYS_NDIR_H
146 #  include <sys/ndir.h>
147 # endif /* HAVE_SYS_NDIR_H */
148 # ifdef HAVE_SYS_DIR_H
149 #  include <sys/dir.h>
150 # endif /* HAVE_SYS_DIR_H */
151 # ifdef HAVE_NDIR_H
152 #  include <ndir.h>
153 # endif /* HAVE_NDIR_H */
154 #endif /* HAVE_DIRENT_H */
155
156 #ifdef __GNUC__
157 # undef alloca
158 # define alloca __builtin_alloca
159 #else
160 # ifdef HAVE_ALLOCA_H
161 #  include <alloca.h>
162 # else
163 #  ifndef _AIX
164 /* AIX alloca decl has to be the first thing in the file, bletch! */
165 char *alloca ();
166 #  endif
167 # endif
168 #endif
169
170 #include <ctype.h>
171
172 #if HAVE_SYS_MMAN_H
173 #include <sys/mman.h>
174 #endif
175
176 /* XXX FIXME: popt on sunos4.1.3: <sys/resource.h> requires <sys/time.h> */
177 #if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
178 #include <sys/resource.h>
179 #endif
180
181 #if HAVE_SYS_UTSNAME_H
182 #include <sys/utsname.h>
183 #endif
184
185 #if HAVE_SYS_WAIT_H
186 #include <sys/wait.h>
187 #endif
188
189 #if HAVE_GETOPT_H
190 #include <getopt.h>
191 #endif
192
193 #if HAVE_GRP_H
194 #include <grp.h>
195 #endif
196
197 #if HAVE_LIMITS_H
198 #include <limits.h>
199 #endif
200
201 #if HAVE_ERR_H
202 #include <err.h>
203 #endif
204
205 #if HAVE_MALLOC_H
206 #include <malloc.h>
207 #endif
208
209 /*@-declundef@*/
210 /*@mayexit@*/ /*@only@*/ void * xmalloc (size_t size)                   /*@*/;
211 /*@mayexit@*/ /*@only@*/ void * xcalloc (size_t nmemb, size_t size)     /*@*/;
212 /*@mayexit@*/ /*@only@*/ void * xrealloc (/*@only@*//*@null@*/ void * ptr,
213                                         size_t size) /*@*/;
214 /*@mayexit@*/ /*@only@*/ char * xstrdup (const char *str)               /*@*/;
215 /*@=declundef@*/
216 /*@unused@*/ /*@exits@*/ /*@only@*/ void * vmefail(size_t size);
217
218 #if HAVE_MCHECK_H
219 #include <mcheck.h>
220 #endif
221
222
223 /* Memory allocation via macro defs to get meaningful locations from mtrace() */
224 #if HAVE_MCHECK_H && defined(__GNUC__)
225 #define xmalloc(_size)          (malloc(_size) ? : vmefail(_size))
226 #define xcalloc(_nmemb, _size)  (calloc((_nmemb), (_size)) ? : vmefail(_size))
227 #define xrealloc(_ptr, _size)   (realloc((_ptr), (_size)) ? : vmefail(_size))
228 #define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail(strlen(_str)+1)), (_str)))
229 #endif  /* HAVE_MCHECK_H && defined(__GNUC__) */
230
231 /* Retrofit glibc __progname */
232 #if defined __GLIBC__ && __GLIBC__ >= 2
233 #if __GLIBC_MINOR__ >= 1
234 #define __progname      __assert_program_name
235 #endif
236 #define setprogname(pn)
237 #else
238 #define __progname      program_name
239 #define setprogname(pn) \
240   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
241     else __progname = pn;               \
242   }
243 #endif
244 const char *__progname;
245
246 #if HAVE_NETDB_H
247 #ifndef __LCLINT__
248 #include <netdb.h>
249 #endif  /* __LCLINT__ */
250 #endif
251
252 #if HAVE_PWD_H
253 #include <pwd.h>
254 #endif
255
256 /* Take care of NLS matters.  */
257
258 #if HAVE_LOCALE_H
259 # include <locale.h>
260 #endif
261 #if !HAVE_SETLOCALE
262 # define setlocale(Category, Locale) /* empty */
263 #endif
264
265 #if ENABLE_NLS && !defined(__LCLINT__)
266 # include <libintl.h>
267 # define _(Text) gettext (Text)
268 #else
269 # undef bindtextdomain
270 # define bindtextdomain(Domain, Directory) /* empty */
271 # undef textdomain
272 # define textdomain(Domain) /* empty */
273 # define _(Text) Text
274 # undef dgettext
275 # define dgettext(DomainName, Text) Text
276 #endif
277
278 #define N_(Text) Text
279
280 /* ============== from misc/miscfn.h */
281
282 #if !defined(USE_GNU_GLOB)
283 #if HAVE_FNMATCH_H
284 #include <fnmatch.h>
285 #endif
286
287 #if HAVE_GLOB_H
288 #include <glob.h>
289 #endif
290 #else
291 #include "misc/glob.h"
292 #include "misc/fnmatch.h"
293 #endif
294
295 #if ! HAVE_S_IFSOCK
296 #define S_IFSOCK (0xC000)
297 #endif
298
299 #if ! HAVE_S_ISLNK
300 #define S_ISLNK(mode) ((mode & 0xF000) == S_IFLNK)
301 #endif
302
303 #if ! HAVE_S_ISSOCK
304 #define S_ISSOCK(mode) ((mode & 0xF000) == S_IFSOCK)
305 #endif
306
307 #if NEED_STRINGS_H
308 #include <strings.h>
309 #endif
310
311 #if ! HAVE_REALPATH
312 char *realpath(const char *path, char resolved_path []);
313 #endif
314
315 #if NEED_MYREALLOC
316 #define realloc(ptr,size) myrealloc(ptr,size)
317 extern void *myrealloc(void *, size_t);
318 #endif
319
320 #if ! HAVE_SETENV
321 extern int setenv(const char *name, const char *value, int replace);
322 extern void unsetenv(const char *name);
323 #endif
324
325 #if HAVE_SYS_SOCKET_H
326 #include <sys/types.h>
327 #ifndef __LCLINT__
328 #include <sys/socket.h>
329 #endif  /* __LCLINT__ */
330 #endif
331
332 #if HAVE_SYS_SELECT_H
333 #include <sys/select.h>
334 #endif
335
336 /* Solaris <= 2.6 limits getpass return to only 8 chars */
337 #if HAVE_GETPASSPHRASE
338 #define getpass getpassphrase
339 #endif
340
341 #if ! HAVE_LCHOWN
342 #define lchown chown
343 #endif
344
345 #if HAVE_GETMNTINFO_R || HAVE_MNTCTL
346 # define GETMNTENT_ONE 0
347 # define GETMNTENT_TWO 0
348 # if HAVE_SYS_MNTCTL_H
349 #  include <sys/mntctl.h>
350 # endif
351 # if HAVE_SYS_VMOUNT_H
352 #  include <sys/vmount.h>
353 # endif
354 # if HAVE_SYS_MOUNT_H
355 #  include <sys/mount.h>
356 # endif
357 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
358 # if HAVE_MNTENT_H
359 #  include <stdio.h>
360 #  include <mntent.h>
361 #  define our_mntent struct mntent
362 #  define our_mntdir mnt_dir
363 # elif HAVE_STRUCT_MNTTAB
364 #  include <stdio.h>
365 #  include <mnttab.h>
366    struct our_mntent {
367        char * our_mntdir;
368    };
369    struct our_mntent *getmntent(FILE *filep);
370 #  define our_mntent struct our_mntent
371 # else
372 #  include <stdio.h>
373    struct our_mntent {
374        char * our_mntdir;
375    };
376    struct our_mntent *getmntent(FILE *filep);
377 #  define our_mntent struct our_mntent
378 # endif
379 # define GETMNTENT_ONE 1
380 # define GETMNTENT_TWO 0
381 #elif HAVE_SYS_MNTTAB_H
382 # include <stdio.h>
383 # include <sys/mnttab.h>
384 # define GETMNTENT_ONE 0
385 # define GETMNTENT_TWO 1
386 # define our_mntent struct mnttab
387 # define our_mntdir mnt_mountp
388 #else /* if !HAVE_MNTCTL */
389 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
390 #endif
391
392 #ifndef MOUNTED
393 #define MOUNTED "/etc/mnttab"
394 #endif
395 #endif  /* H_SYSTEM */