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