rpm 4.8.1
system.h
Go to the documentation of this file.
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 /* <unistd.h> should be included before any preprocessor test
00022    of _POSIX_VERSION.  */
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 /* __APPLE__ */
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 /* Since major is a function on SVR4, we can't use `ifndef major'.  */
00047 #if MAJOR_IN_MKDEV
00048 #include <sys/mkdev.h>
00049 #define HAVE_MAJOR
00050 #endif
00051 #if MAJOR_IN_SYSMACROS
00052 #include <sys/sysmacros.h>
00053 #define HAVE_MAJOR
00054 #endif
00055 #ifdef major                    /* Might be defined in sys/types.h.  */
00056 #define HAVE_MAJOR
00057 #endif
00058 
00059 #ifndef HAVE_MAJOR
00060 #define major(dev)  (((dev) >> 8) & 0xff)
00061 #define minor(dev)  ((dev) & 0xff)
00062 #define makedev(maj, min)  (((maj) << 8) | (min))
00063 #endif
00064 #undef HAVE_MAJOR
00065 
00066 #ifdef HAVE_UTIME_H
00067 #include <utime.h>
00068 #endif
00069 
00070 #ifdef HAVE_STRING_H
00071 # if !STDC_HEADERS && HAVE_MEMORY_H
00072 #  include <memory.h>
00073 # endif
00074 # include <string.h>
00075 #else
00076 # include <strings.h>
00077 char *memchr ();
00078 #endif
00079 
00080 #if !defined(HAVE_STPCPY)
00081 char * stpcpy(char * dest, const char * src);
00082 #endif
00083 
00084 #if !defined(HAVE_STPNCPY)
00085 char * stpncpy(char * dest, const char * src, size_t n);
00086 #endif
00087 
00088 #include <errno.h>
00089 #ifndef errno
00090 extern int errno;
00091 #endif
00092 
00093 #if HAVE_ERROR && HAVE_ERROR_H
00094 #include <error.h>
00095 #endif
00096 
00097 #if HAVE___SECURE_GETENV
00098 #define getenv(_s)      __secure_getenv(_s)
00099 #endif
00100 
00101 #ifdef STDC_HEADERS
00102 /* FIX: shrug */
00103 #define getopt system_getopt
00104 #include <stdlib.h>
00105 #undef getopt
00106 #else /* not STDC_HEADERS */
00107 char *getenv (const char *name);
00108 #if ! HAVE_REALPATH
00109 char *realpath(const char *path, char resolved_path []);
00110 #endif
00111 #endif /* STDC_HEADERS */
00112 
00113 /* XXX solaris2.5.1 has not */
00114 #if !defined(EXIT_FAILURE)
00115 #define EXIT_FAILURE    1
00116 #endif
00117 
00118 #ifdef HAVE_FCNTL_H
00119 #include <fcntl.h>
00120 #else
00121 #include <sys/file.h>
00122 #endif
00123 
00124 #if !defined(SEEK_SET)
00125 #define SEEK_SET 0
00126 #define SEEK_CUR 1
00127 #define SEEK_END 2
00128 #endif
00129 #if !defined(F_OK) 
00130 #define F_OK 0
00131 #define X_OK 1
00132 #define W_OK 2
00133 #define R_OK 4
00134 #endif
00135 
00136 #ifdef HAVE_DIRENT_H
00137 # include <dirent.h>
00138 # define NLENGTH(direct) (strlen((direct)->d_name))
00139 #else /* not HAVE_DIRENT_H */
00140 # define dirent direct
00141 # define NLENGTH(direct) ((direct)->d_namlen)
00142 # ifdef HAVE_SYS_NDIR_H
00143 #  include <sys/ndir.h>
00144 # endif /* HAVE_SYS_NDIR_H */
00145 # ifdef HAVE_SYS_DIR_H
00146 #  include <sys/dir.h>
00147 # endif /* HAVE_SYS_DIR_H */
00148 # ifdef HAVE_NDIR_H
00149 #  include <ndir.h>
00150 # endif /* HAVE_NDIR_H */
00151 #endif /* HAVE_DIRENT_H */
00152 
00153 #include <ctype.h>
00154 
00155 #if HAVE_SYS_MMAN_H
00156 #include <sys/mman.h>
00157 #endif
00158 
00159 /* XXX FIXME: popt on sunos4.1.3: <sys/resource.h> requires <sys/time.h> */
00160 #if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
00161 #include <sys/resource.h>
00162 #endif
00163 
00164 #if HAVE_SYS_UTSNAME_H
00165 #include <sys/utsname.h>
00166 #endif
00167 
00168 #if HAVE_SYS_WAIT_H
00169 #include <sys/wait.h>
00170 #endif
00171 
00172 #if HAVE_GETOPT_H
00173 #include <getopt.h>
00174 #endif
00175 
00176 #if HAVE_GRP_H
00177 #include <grp.h>
00178 #endif
00179 
00180 #if HAVE_LIMITS_H
00181 #include <limits.h>
00182 #endif
00183 
00184 #ifndef PATH_MAX
00185 #ifdef _POSIX_PATH_MAX
00186 #define PATH_MAX _POSIX_PATH_MAX
00187 #elif defined MAXPATHLEN
00188 #define PATH_MAX MAXPATHLEN
00189 #else
00190 #define PATH_MAX 256
00191 #endif
00192 #endif
00193 
00194 #if HAVE_ERR_H
00195 #include <err.h>
00196 #endif
00197 
00198 #if HAVE_MALLOC_H 
00199 #include <malloc.h>
00200 #endif
00201 
00202 #if WITH_SELINUX
00203 #include <selinux/selinux.h>
00204 #else
00205 typedef char * security_context_t;
00206 
00207 #define freecon(_c)
00208 
00209 #define getfilecon(_fn, _c)     (-1)
00210 #define lgetfilecon(_fn, _c)    (-1)
00211 #define fgetfilecon(_fd, _c)    (-1)
00212 
00213 #define setfilecon(_fn, _c)     (-1)
00214 #define lsetfilecon(_fn, _c)    (-1)
00215 #define fsetfilecon(_fd, _c)    (-1)
00216 
00217 #define security_check_context(_c)      (0)
00218 
00219 #define is_selinux_enabled()    (0)
00220 
00221 #define matchpathcon_init(_fn)                  (-1)
00222 #define matchpathcon_fini()                     (0)
00223 #define matchpathcon(_fn, _fm, _c)              (-1)
00224 
00225 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
00226 #endif
00227 
00228 #if WITH_CAP
00229 #include <sys/capability.h>
00230 #else
00231 typedef void * cap_t;
00232 #endif
00233 
00234 #if WITH_ACL
00235 #include <acl/libacl.h>
00236 #endif
00237 
00238 #if HAVE_MCHECK_H
00239 #include <mcheck.h>
00240 #endif  /* HAVE_MCHECK_H */
00241 
00242 #include "rpmio/rpmutil.h"
00243 /* compatibility macros to avoid a mass-renaming all over the codebase */
00244 #define xmalloc(_size) rmalloc((_size))
00245 #define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
00246 #define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
00247 #define xstrdup(_str) rstrdup((_str))
00248 #define _free(_ptr) rfree((_ptr))
00249 #define _constfree(_ptr) rfree((void *)(_ptr))
00250 
00251 /* Retrofit glibc __progname */
00252 #if defined __GLIBC__ && __GLIBC__ >= 2
00253 #if __GLIBC_MINOR__ >= 1
00254 #define __progname      __assert_program_name
00255 #endif
00256 #define setprogname(pn)
00257 #else
00258 #define __progname      program_name
00259 #define setprogname(pn) \
00260   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
00261     else __progname = pn;               \
00262   }
00263 #endif
00264 extern const char *__progname;
00265 
00266 #if HAVE_NETDB_H
00267 #include <netdb.h>
00268 #endif
00269 
00270 #if HAVE_PWD_H
00271 #include <pwd.h>
00272 #endif
00273 
00274 /* Take care of NLS matters.  */
00275 
00276 #if HAVE_LOCALE_H
00277 # include <locale.h>
00278 #endif
00279 #if !HAVE_SETLOCALE
00280 # define setlocale(Category, Locale) /* empty */
00281 #endif
00282 
00283 #if ENABLE_NLS
00284 # include <libintl.h>
00285 # define _(Text) dgettext (PACKAGE, Text)
00286 #else
00287 # undef bindtextdomain
00288 # define bindtextdomain(Domain, Directory) /* empty */
00289 # undef textdomain
00290 # define textdomain(Domain) /* empty */
00291 # define _(Text) Text
00292 # undef dgettext
00293 # define dgettext(DomainName, Text) Text
00294 #endif
00295 
00296 #define N_(Text) Text
00297 
00298 /* ============== from misc/miscfn.h */
00299 
00300 #if !defined(USE_GNU_GLOB) 
00301 #if HAVE_FNMATCH_H
00302 #include <fnmatch.h>
00303 #endif
00304 
00305 #if HAVE_GLOB_H 
00306 #include <glob.h>
00307 #endif
00308 #else
00309 #include "misc/glob.h"
00310 #include "misc/fnmatch.h"
00311 #endif
00312 
00313 #if ! HAVE_S_IFSOCK
00314 #define S_IFSOCK (0xc000)
00315 #endif
00316 
00317 #if ! HAVE_S_ISLNK
00318 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
00319 #endif
00320 
00321 #if ! HAVE_S_ISSOCK
00322 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
00323 #endif
00324 
00325 #if NEED_STRINGS_H
00326 #include <strings.h>
00327 #endif
00328 
00329 #if NEED_MYREALLOC
00330 #define realloc(ptr,size) myrealloc(ptr,size)
00331 extern void *myrealloc(void *, size_t);
00332 #endif
00333 
00334 #if ! HAVE_SETENV
00335 extern int setenv(const char *name, const char *value, int replace);
00336 extern void unsetenv(const char *name);
00337 #endif
00338 
00339 #if HAVE_SYS_SOCKET_H
00340 #include <sys/types.h>
00341 #include <sys/socket.h>
00342 #endif
00343 
00344 #if HAVE_POLL_H
00345 #include <poll.h>
00346 #else
00347 #if HAVE_SYS_SELECT_H
00348 #include <sys/select.h>
00349 #endif
00350 #endif
00351 
00352 /* Solaris <= 2.6 limits getpass return to only 8 chars */
00353 #if HAVE_GETPASSPHRASE
00354 #define getpass getpassphrase
00355 #endif
00356 
00357 #if ! HAVE_LCHOWN
00358 #define lchown chown
00359 #endif
00360 
00361 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
00362 # define GETMNTENT_ONE 0
00363 # define GETMNTENT_TWO 0
00364 # if HAVE_SYS_MNTCTL_H
00365 #  include <sys/mntctl.h>
00366 # endif
00367 # if HAVE_SYS_VMOUNT_H
00368 #  include <sys/vmount.h>
00369 # endif
00370 # if HAVE_SYS_MOUNT_H
00371 #  include <sys/mount.h>
00372 # endif
00373 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
00374 # if HAVE_MNTENT_H
00375 #  include <stdio.h>
00376 #  include <mntent.h>
00377 #  define our_mntent struct mntent
00378 #  define our_mntdir mnt_dir
00379 # elif HAVE_STRUCT_MNTTAB
00380 #  include <stdio.h>
00381 #  include <mnttab.h>
00382    struct our_mntent {
00383        char * our_mntdir;
00384    };
00385    struct our_mntent *getmntent(FILE *filep);
00386 #  define our_mntent struct our_mntent
00387 # else
00388 #  include <stdio.h>
00389    struct our_mntent {
00390        char * our_mntdir;
00391    };
00392    struct our_mntent *getmntent(FILE *filep);
00393 #  define our_mntent struct our_mntent
00394 # endif
00395 # define GETMNTENT_ONE 1
00396 # define GETMNTENT_TWO 0
00397 #elif HAVE_SYS_MNTTAB_H
00398 # include <stdio.h>
00399 # include <sys/mnttab.h>
00400 # define GETMNTENT_ONE 0
00401 # define GETMNTENT_TWO 1
00402 # define our_mntent struct mnttab
00403 # define our_mntdir mnt_mountp
00404 #else /* if !HAVE_MNTCTL */
00405 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
00406 #endif
00407 
00408 #ifndef MOUNTED
00409 #define MOUNTED "/etc/mnttab"
00410 #endif
00411 
00412 #endif  /* H_SYSTEM */