00001
00005 #ifndef H_SYSTEM
00006 #define H_SYSTEM
00007
00008 #ifdef HAVE_CONFIG_H
00009 #include "config.h"
00010 #endif
00011
00012 #include <sys/types.h>
00013
00014 #include <sys/stat.h>
00015 #include <stdio.h>
00016
00017 #ifdef HAVE_SYS_PARAM_H
00018 #include <sys/param.h>
00019 #endif
00020
00021
00022
00023 #ifdef HAVE_UNISTD_H
00024 #include <unistd.h>
00025 #if !defined(__GLIBC__)
00026 #ifdef __APPLE__
00027 #include <crt_externs.h>
00028 #define environ (*_NSGetEnviron())
00029 #else
00030 extern char ** environ;
00031 #endif
00032 #endif
00033 #endif
00034
00035 #if TIME_WITH_SYS_TIME
00036 # include <sys/time.h>
00037 # include <time.h>
00038 #else
00039 # if HAVE_SYS_TIME_H
00040 # include <sys/time.h>
00041 # else
00042 # include <time.h>
00043 # endif
00044 #endif
00045
00046 #if NEED_TIMEZONE
00047 extern time_t timezone;
00048 #endif
00049
00050
00051 #if MAJOR_IN_MKDEV
00052 #include <sys/mkdev.h>
00053 #define HAVE_MAJOR
00054 #endif
00055 #if MAJOR_IN_SYSMACROS
00056 #include <sys/sysmacros.h>
00057 #define HAVE_MAJOR
00058 #endif
00059 #ifdef major
00060 #define HAVE_MAJOR
00061 #endif
00062
00063 #ifndef HAVE_MAJOR
00064 #define major(dev) (((dev) >> 8) & 0xff)
00065 #define minor(dev) ((dev) & 0xff)
00066 #define makedev(maj, min) (((maj) << 8) | (min))
00067 #endif
00068 #undef HAVE_MAJOR
00069
00070 #ifdef HAVE_UTIME_H
00071 #include <utime.h>
00072 #endif
00073
00074 #ifdef HAVE_STRING_H
00075 # if !STDC_HEADERS && HAVE_MEMORY_H
00076 # include <memory.h>
00077 # endif
00078 # include <string.h>
00079 #else
00080 # include <strings.h>
00081 char *memchr ();
00082 #endif
00083
00084 #if !defined(HAVE_STPCPY)
00085 char * stpcpy(char * dest, const char * src);
00086 #endif
00087
00088 #if !defined(HAVE_STPNCPY)
00089 char * stpncpy(char * dest, const char * src, size_t n);
00090 #endif
00091
00092 #include <errno.h>
00093 #ifndef errno
00094 extern int errno;
00095 #endif
00096
00097 #if HAVE_ERROR && HAVE_ERROR_H
00098 #include <error.h>
00099 #endif
00100
00101 #if HAVE___SECURE_GETENV
00102 #define getenv(_s) __secure_getenv(_s)
00103 #endif
00104
00105 #ifdef STDC_HEADERS
00106
00107 #define getopt system_getopt
00108 #include <stdlib.h>
00109 #undef getopt
00110 #else
00111 char *getenv (const char *name);
00112 #if ! HAVE_REALPATH
00113 char *realpath(const char *path, char resolved_path []);
00114 #endif
00115 #endif
00116
00117
00118 #if !defined(EXIT_FAILURE)
00119 #define EXIT_FAILURE 1
00120 #endif
00121
00122 #ifdef HAVE_FCNTL_H
00123 #include <fcntl.h>
00124 #else
00125 #include <sys/file.h>
00126 #endif
00127
00128 #if !defined(SEEK_SET)
00129 #define SEEK_SET 0
00130 #define SEEK_CUR 1
00131 #define SEEK_END 2
00132 #endif
00133 #if !defined(F_OK)
00134 #define F_OK 0
00135 #define X_OK 1
00136 #define W_OK 2
00137 #define R_OK 4
00138 #endif
00139
00140 #ifdef HAVE_DIRENT_H
00141 # include <dirent.h>
00142 # define NLENGTH(direct) (strlen((direct)->d_name))
00143 #else
00144 # define dirent direct
00145 # define NLENGTH(direct) ((direct)->d_namlen)
00146 # ifdef HAVE_SYS_NDIR_H
00147 # include <sys/ndir.h>
00148 # endif
00149 # ifdef HAVE_SYS_DIR_H
00150 # include <sys/dir.h>
00151 # endif
00152 # ifdef HAVE_NDIR_H
00153 # include <ndir.h>
00154 # endif
00155 #endif
00156
00157 #include <ctype.h>
00158
00159 #if HAVE_SYS_MMAN_H
00160 #include <sys/mman.h>
00161 #endif
00162
00163
00164 #if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
00165 #include <sys/resource.h>
00166 #endif
00167
00168 #if HAVE_SYS_UTSNAME_H
00169 #include <sys/utsname.h>
00170 #endif
00171
00172 #if HAVE_SYS_WAIT_H
00173 #include <sys/wait.h>
00174 #endif
00175
00176 #if HAVE_GETOPT_H
00177 #include <getopt.h>
00178 #endif
00179
00180 #if HAVE_GRP_H
00181 #include <grp.h>
00182 #endif
00183
00184 #if HAVE_LIMITS_H
00185 #include <limits.h>
00186 #endif
00187
00188 #ifndef PATH_MAX
00189 #ifdef _POSIX_PATH_MAX
00190 #define PATH_MAX _POSIX_PATH_MAX
00191 #elif defined MAXPATHLEN
00192 #define PATH_MAX MAXPATHLEN
00193 #else
00194 #define PATH_MAX 256
00195 #endif
00196 #endif
00197
00198 #if HAVE_ERR_H
00199 #include <err.h>
00200 #endif
00201
00202 #if HAVE_MALLOC_H
00203 #include <malloc.h>
00204 #endif
00205
00206 #if WITH_SELINUX
00207 #include <selinux/selinux.h>
00208 #else
00209 typedef char * security_context_t;
00210
00211 #define freecon(_c)
00212
00213 #define getfilecon(_fn, _c) (-1)
00214 #define lgetfilecon(_fn, _c) (-1)
00215 #define fgetfilecon(_fd, _c) (-1)
00216
00217 #define setfilecon(_fn, _c) (-1)
00218 #define lsetfilecon(_fn, _c) (-1)
00219 #define fsetfilecon(_fd, _c) (-1)
00220
00221 #define security_check_context(_c) (0)
00222
00223 #define is_selinux_enabled() (0)
00224
00225 #define matchpathcon_init(_fn) (-1)
00226 #define matchpathcon_fini() (0)
00227 #define matchpathcon(_fn, _fm, _c) (-1)
00228
00229 #define rpm_execcon(_v, _fn, _av, _envp) (0)
00230 #endif
00231
00237 static inline
00238 void * _free(void * p)
00239 {
00240 if (p != NULL) free(p);
00241 return NULL;
00242 }
00243
00251 static inline
00252 void * _constfree(const void * p)
00253 {
00254 if (p != NULL) free((void *)p);
00255 return NULL;
00256 }
00257
00258
00261 void * xmalloc (size_t size);
00262
00265 void * xcalloc (size_t nmemb, size_t size);
00266
00270 void * xrealloc (void * ptr,
00271 size_t size);
00272
00275 char * xstrdup (const char *str);
00276
00279 void * vmefail(size_t size);
00280
00281 #if HAVE_MCHECK_H
00282 #include <mcheck.h>
00283
00284 #if defined(__GNUC__)
00285 #define xmalloc(_size) (malloc(_size) ? : vmefail(_size))
00286 #define xcalloc(_nmemb, _size) (calloc((_nmemb), (_size)) ? : vmefail(_size))
00287 #define xrealloc(_ptr, _size) (realloc((_ptr), (_size)) ? : vmefail(_size))
00288 #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail(strlen(_str)+1)), (_str)))
00289 #endif
00290 #endif
00291
00292
00293 #if defined __GLIBC__ && __GLIBC__ >= 2
00294 #if __GLIBC_MINOR__ >= 1
00295 #define __progname __assert_program_name
00296 #endif
00297 #define setprogname(pn)
00298 #else
00299 #define __progname program_name
00300 #define setprogname(pn) \
00301 { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
00302 else __progname = pn; \
00303 }
00304 #endif
00305 extern const char *__progname;
00306
00307 #if HAVE_NETDB_H
00308 #include <netdb.h>
00309 #endif
00310
00311 #if HAVE_PWD_H
00312 #include <pwd.h>
00313 #endif
00314
00315
00316
00317 #if HAVE_LOCALE_H
00318 # include <locale.h>
00319 #endif
00320 #if !HAVE_SETLOCALE
00321 # define setlocale(Category, Locale)
00322 #endif
00323
00324 #if ENABLE_NLS
00325 # include <libintl.h>
00326 # define _(Text) dgettext (PACKAGE, Text)
00327 #else
00328 # undef bindtextdomain
00329 # define bindtextdomain(Domain, Directory)
00330 # undef textdomain
00331 # define textdomain(Domain)
00332 # define _(Text) Text
00333 # undef dgettext
00334 # define dgettext(DomainName, Text) Text
00335 #endif
00336
00337 #define N_(Text) Text
00338
00339
00340
00341 #if !defined(USE_GNU_GLOB)
00342 #if HAVE_FNMATCH_H
00343 #include <fnmatch.h>
00344 #endif
00345
00346 #if HAVE_GLOB_H
00347 #include <glob.h>
00348 #endif
00349 #else
00350 #include "misc/glob.h"
00351 #include "misc/fnmatch.h"
00352 #endif
00353
00354 #if ! HAVE_S_IFSOCK
00355 #define S_IFSOCK (0xc000)
00356 #endif
00357
00358 #if ! HAVE_S_ISLNK
00359 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
00360 #endif
00361
00362 #if ! HAVE_S_ISSOCK
00363 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
00364 #endif
00365
00366 #if NEED_STRINGS_H
00367 #include <strings.h>
00368 #endif
00369
00370 #if NEED_MYREALLOC
00371 #define realloc(ptr,size) myrealloc(ptr,size)
00372 extern void *myrealloc(void *, size_t);
00373 #endif
00374
00375 #if ! HAVE_SETENV
00376 extern int setenv(const char *name, const char *value, int replace);
00377 extern void unsetenv(const char *name);
00378 #endif
00379
00380 #if HAVE_SYS_SOCKET_H
00381 #include <sys/types.h>
00382 #include <sys/socket.h>
00383 #endif
00384
00385 #if HAVE_POLL_H
00386 #include <poll.h>
00387 #else
00388 #if HAVE_SYS_SELECT_H
00389 #include <sys/select.h>
00390 #endif
00391 #endif
00392
00393
00394 #if HAVE_GETPASSPHRASE
00395 #define getpass getpassphrase
00396 #endif
00397
00398 #if ! HAVE_LCHOWN
00399 #define lchown chown
00400 #endif
00401
00402 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
00403 # define GETMNTENT_ONE 0
00404 # define GETMNTENT_TWO 0
00405 # if HAVE_SYS_MNTCTL_H
00406 # include <sys/mntctl.h>
00407 # endif
00408 # if HAVE_SYS_VMOUNT_H
00409 # include <sys/vmount.h>
00410 # endif
00411 # if HAVE_SYS_MOUNT_H
00412 # include <sys/mount.h>
00413 # endif
00414 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
00415 # if HAVE_MNTENT_H
00416 # include <stdio.h>
00417 # include <mntent.h>
00418 # define our_mntent struct mntent
00419 # define our_mntdir mnt_dir
00420 # elif HAVE_STRUCT_MNTTAB
00421 # include <stdio.h>
00422 # include <mnttab.h>
00423 struct our_mntent {
00424 char * our_mntdir;
00425 };
00426 struct our_mntent *getmntent(FILE *filep);
00427 # define our_mntent struct our_mntent
00428 # else
00429 # include <stdio.h>
00430 struct our_mntent {
00431 char * our_mntdir;
00432 };
00433 struct our_mntent *getmntent(FILE *filep);
00434 # define our_mntent struct our_mntent
00435 # endif
00436 # define GETMNTENT_ONE 1
00437 # define GETMNTENT_TWO 0
00438 #elif HAVE_SYS_MNTTAB_H
00439 # include <stdio.h>
00440 # include <sys/mnttab.h>
00441 # define GETMNTENT_ONE 0
00442 # define GETMNTENT_TWO 1
00443 # define our_mntent struct mnttab
00444 # define our_mntdir mnt_mountp
00445 #else
00446 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
00447 #endif
00448
00449 #ifndef MOUNTED
00450 #define MOUNTED "/etc/mnttab"
00451 #endif
00452
00453 #endif