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 #if HAVE_ERR_H
00189 #include <err.h>
00190 #endif
00191
00192 #if HAVE_MALLOC_H
00193 #include <malloc.h>
00194 #endif
00195
00196 #if WITH_SELINUX
00197 #include <selinux/selinux.h>
00198 #else
00199 typedef char * security_context_t;
00200
00201 #define freecon(_c)
00202
00203 #define getfilecon(_fn, _c) (-1)
00204 #define lgetfilecon(_fn, _c) (-1)
00205 #define fgetfilecon(_fd, _c) (-1)
00206
00207 #define setfilecon(_fn, _c) (-1)
00208 #define lsetfilecon(_fn, _c) (-1)
00209 #define fsetfilecon(_fd, _c) (-1)
00210
00211 #define security_check_context(_c) (0)
00212
00213 #define is_selinux_enabled() (0)
00214
00215 #define matchpathcon_init(_fn) (-1)
00216 #define matchpathcon_fini() (0)
00217 #define matchpathcon(_fn, _fm, _c) (-1)
00218
00219 #define rpm_execcon(_v, _fn, _av, _envp) (0)
00220 #endif
00221
00227 static inline
00228 void * _free(void * p)
00229 {
00230 if (p != NULL) free(p);
00231 return NULL;
00232 }
00233
00241 static inline
00242 void * _constfree(const void * p)
00243 {
00244 if (p != NULL) free((void *)p);
00245 return NULL;
00246 }
00247
00248
00251 void * xmalloc (size_t size);
00252
00255 void * xcalloc (size_t nmemb, size_t size);
00256
00260 void * xrealloc (void * ptr,
00261 size_t size);
00262
00265 char * xstrdup (const char *str);
00266
00269 void * vmefail(size_t size);
00270
00271 #if HAVE_MCHECK_H
00272 #include <mcheck.h>
00273
00274 #if defined(__GNUC__)
00275 #define xmalloc(_size) (malloc(_size) ? : vmefail(_size))
00276 #define xcalloc(_nmemb, _size) (calloc((_nmemb), (_size)) ? : vmefail(_size))
00277 #define xrealloc(_ptr, _size) (realloc((_ptr), (_size)) ? : vmefail(_size))
00278 #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail(strlen(_str)+1)), (_str)))
00279 #endif
00280 #endif
00281
00282
00283 #if defined __GLIBC__ && __GLIBC__ >= 2
00284 #if __GLIBC_MINOR__ >= 1
00285 #define __progname __assert_program_name
00286 #endif
00287 #define setprogname(pn)
00288 #else
00289 #define __progname program_name
00290 #define setprogname(pn) \
00291 { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
00292 else __progname = pn; \
00293 }
00294 #endif
00295 extern const char *__progname;
00296
00297 #if HAVE_NETDB_H
00298 #include <netdb.h>
00299 #endif
00300
00301 #if HAVE_PWD_H
00302 #include <pwd.h>
00303 #endif
00304
00305
00306
00307 #if HAVE_LOCALE_H
00308 # include <locale.h>
00309 #endif
00310 #if !HAVE_SETLOCALE
00311 # define setlocale(Category, Locale)
00312 #endif
00313
00314 #if ENABLE_NLS
00315 # include <libintl.h>
00316 # define _(Text) dgettext (PACKAGE, Text)
00317 #else
00318 # undef bindtextdomain
00319 # define bindtextdomain(Domain, Directory)
00320 # undef textdomain
00321 # define textdomain(Domain)
00322 # define _(Text) Text
00323 # undef dgettext
00324 # define dgettext(DomainName, Text) Text
00325 #endif
00326
00327 #define N_(Text) Text
00328
00329
00330
00331 #if !defined(USE_GNU_GLOB)
00332 #if HAVE_FNMATCH_H
00333 #include <fnmatch.h>
00334 #endif
00335
00336 #if HAVE_GLOB_H
00337 #include <glob.h>
00338 #endif
00339 #else
00340 #include "misc/glob.h"
00341 #include "misc/fnmatch.h"
00342 #endif
00343
00344 #if ! HAVE_S_IFSOCK
00345 #define S_IFSOCK (0xc000)
00346 #endif
00347
00348 #if ! HAVE_S_ISLNK
00349 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
00350 #endif
00351
00352 #if ! HAVE_S_ISSOCK
00353 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
00354 #endif
00355
00356 #if NEED_STRINGS_H
00357 #include <strings.h>
00358 #endif
00359
00360 #if NEED_MYREALLOC
00361 #define realloc(ptr,size) myrealloc(ptr,size)
00362 extern void *myrealloc(void *, size_t);
00363 #endif
00364
00365 #if ! HAVE_SETENV
00366 extern int setenv(const char *name, const char *value, int replace);
00367 extern void unsetenv(const char *name);
00368 #endif
00369
00370 #if HAVE_SYS_SOCKET_H
00371 #include <sys/types.h>
00372 #include <sys/socket.h>
00373 #endif
00374
00375 #if HAVE_POLL_H
00376 #include <poll.h>
00377 #else
00378 #if HAVE_SYS_SELECT_H
00379 #include <sys/select.h>
00380 #endif
00381 #endif
00382
00383
00384 #if HAVE_GETPASSPHRASE
00385 #define getpass getpassphrase
00386 #endif
00387
00388 #if ! HAVE_LCHOWN
00389 #define lchown chown
00390 #endif
00391
00392 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
00393 # define GETMNTENT_ONE 0
00394 # define GETMNTENT_TWO 0
00395 # if HAVE_SYS_MNTCTL_H
00396 # include <sys/mntctl.h>
00397 # endif
00398 # if HAVE_SYS_VMOUNT_H
00399 # include <sys/vmount.h>
00400 # endif
00401 # if HAVE_SYS_MOUNT_H
00402 # include <sys/mount.h>
00403 # endif
00404 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
00405 # if HAVE_MNTENT_H
00406 # include <stdio.h>
00407 # include <mntent.h>
00408 # define our_mntent struct mntent
00409 # define our_mntdir mnt_dir
00410 # elif HAVE_STRUCT_MNTTAB
00411 # include <stdio.h>
00412 # include <mnttab.h>
00413 struct our_mntent {
00414 char * our_mntdir;
00415 };
00416 struct our_mntent *getmntent(FILE *filep);
00417 # define our_mntent struct our_mntent
00418 # else
00419 # include <stdio.h>
00420 struct our_mntent {
00421 char * our_mntdir;
00422 };
00423 struct our_mntent *getmntent(FILE *filep);
00424 # define our_mntent struct our_mntent
00425 # endif
00426 # define GETMNTENT_ONE 1
00427 # define GETMNTENT_TWO 0
00428 #elif HAVE_SYS_MNTTAB_H
00429 # include <stdio.h>
00430 # include <sys/mnttab.h>
00431 # define GETMNTENT_ONE 0
00432 # define GETMNTENT_TWO 1
00433 # define our_mntent struct mnttab
00434 # define our_mntdir mnt_mountp
00435 #else
00436 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
00437 #endif
00438
00439 #ifndef MOUNTED
00440 #define MOUNTED "/etc/mnttab"
00441 #endif
00442
00443 #endif