Main Page Modules Data Structures File List Data Fields Globals Related Pages

# 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 #if defined(__LCLINT__)
    00015 /*@-redef@*/
    00016 typedef unsigned int u_int32_t;
    00017 typedef unsigned short u_int16_t;
    00018 typedef unsigned char u_int8_t;
    00019 /*@-incondefs@*/        /* LCLint 3.0.0.15 */
    00020 typedef int int32_t;
    00021 /*@=incondefs@*/
    00022 /*@=redef@*/
    00023 #endif
    00024
    00025 #include <sys/stat.h>
    00026 #include <stdio.h>
    00027
    00028 #ifdef HAVE_SYS_PARAM_H
    00029 #include <sys/param.h>
    00030 #endif
    00031
    00032 /* <unistd.h> should be included before any preprocessor test
    00033    of _POSIX_VERSION.  */
    00034 #ifdef HAVE_UNISTD_H
    00035 #include <unistd.h>
    00036 #if defined(__LCLINT__)
    00037 /*@-superuser -declundef -incondefs @*/ /* LCL: modifies clause missing */
    00038 extern int chroot (const char *__path)
    00039         /*@globals errno, systemState @*/
    00040         /*@modifies errno, systemState @*/;
    00041 /*@=superuser =declundef =incondefs @*/
    00042 #endif
    00043 #if !defined(__GLIBC__) && !defined(__LCLINT__)
    00044 extern char ** environ;
    00045 #endif
    00046 #endif
    00047
    00048 #if TIME_WITH_SYS_TIME
    00049 # include <sys/time.h>
    00050 # include <time.h>
    00051 #else
    00052 # if HAVE_SYS_TIME_H
    00053 #  include <sys/time.h>
    00054 # else
    00055 #  include <time.h>
    00056 # endif
    00057 #endif
    00058
    00059 #if NEED_TIMEZONE
    00060 extern time_t timezone;
    00061 #endif
    00062
    00063 /* Since major is a function on SVR4, we can't use `ifndef major'.  */
    00064 #if MAJOR_IN_MKDEV
    00065 #include <sys/mkdev.h>
    00066 #define HAVE_MAJOR
    00067 #endif
    00068 #if MAJOR_IN_SYSMACROS
    00069 #include <sys/sysmacros.h>
    00070 #define HAVE_MAJOR
    00071 #endif
    00072 #ifdef major                    /* Might be defined in sys/types.h.  */
    00073 #define HAVE_MAJOR
    00074 #endif
    00075
    00076 #ifndef HAVE_MAJOR
    00077 #define major(dev)  (((dev) >> 8) & 0xff)
    00078 #define minor(dev)  ((dev) & 0xff)
    00079 #define makedev(maj, min)  (((maj) << 8) | (min))
    00080 #endif
    00081 #undef HAVE_MAJOR
    00082
    00083 #ifdef HAVE_UTIME_H
    00084 #include <utime.h>
    00085 #endif
    00086
    00087 #ifdef HAVE_STRING_H
    00088 # if !STDC_HEADERS && HAVE_MEMORY_H
    00089 #  include <memory.h>
    00090 # endif
    00091 # include <string.h>
    00092 #else
    00093 # include <strings.h>
    00094 char *memchr ();
    00095 #endif
    00096
    00097 #if !defined(HAVE_STPCPY)
    00098 char * stpcpy(/*@out@*/ char * dest, const char * src);
    00099 #endif
    00100
    00101 #if !defined(HAVE_STPNCPY)
    00102 char * stpncpy(/*@out@*/ char * dest, const char * src, size_t n);
    00103 #endif
    00104
    00105 #include <errno.h>
    00106 #ifndef errno
    00107 /*@-declundef @*/
    00108 extern int errno;
    00109 /*@=declundef @*/
    00110 #endif
    00111
    00112 #ifdef STDC_HEADERS
    00113 /*@-macrounrecog -incondefs -globuse -mustmod @*/ /* FIX: shrug */
    00114 #define getopt system_getopt
    00115 /*@=macrounrecog =incondefs =globuse =mustmod @*/
    00116 /*@-skipansiheaders@*/
    00117 #include <stdlib.h>
    00118 /*@=skipansiheaders@*/
    00119 #undef getopt
    00120 #if defined(__LCLINT__)
    00121 /*@-declundef -incondefs @*/    /* LCL: modifies clause missing */
    00122 extern char * realpath (const char * file_name, /*@out@*/ char * resolved_name)
    00123         /*@globals errno, fileSystem @*/
    00124         /*@requires maxSet(resolved_name) >=  (PATH_MAX - 1); @*/
    00125         /*@modifies *resolved_name, errno, fileSystem @*/;
    00126 /*@=declundef =incondefs @*/
    00127 #endif
    00128 #else /* not STDC_HEADERS */
    00129 char *getenv (const char *name);
    00130 #if ! HAVE_REALPATH
    00131 char *realpath(const char *path, char resolved_path []);
    00132 #endif
    00133 #endif /* STDC_HEADERS */
    00134
    00135 /* XXX solaris2.5.1 has not */
    00136 #if !defined(EXIT_FAILURE)
    00137 #define EXIT_FAILURE    1
    00138 #endif
    00139
    00140 #ifdef HAVE_FCNTL_H
    00141 #include <fcntl.h>
    00142 #else
    00143 #include <sys/file.h>
    00144 #endif
    00145
    00146 #if !defined(SEEK_SET) && !defined(__LCLINT__)
    00147 #define SEEK_SET 0
    00148 #define SEEK_CUR 1
    00149 #define SEEK_END 2
    00150 #endif
    00151 #if !defined(F_OK) && !defined(__LCLINT__)
    00152 #define F_OK 0
    00153 #define X_OK 1
    00154 #define W_OK 2
    00155 #define R_OK 4
    00156 #endif
    00157
    00158 #ifdef HAVE_DIRENT_H
    00159 # include <dirent.h>
    00160 # define NLENGTH(direct) (strlen((direct)->d_name))
    00161 #else /* not HAVE_DIRENT_H */
    00162 # define dirent direct
    00163 # define NLENGTH(direct) ((direct)->d_namlen)
    00164 # ifdef HAVE_SYS_NDIR_H
    00165 #  include <sys/ndir.h>
    00166 # endif /* HAVE_SYS_NDIR_H */
    00167 # ifdef HAVE_SYS_DIR_H
    00168 #  include <sys/dir.h>
    00169 # endif /* HAVE_SYS_DIR_H */
    00170 # ifdef HAVE_NDIR_H
    00171 #  include <ndir.h>
    00172 # endif /* HAVE_NDIR_H */
    00173 #endif /* HAVE_DIRENT_H */
    00174
    00175 #if defined(__LCLINT__)
    00176 /*@-declundef -incondefs @*/ /* LCL: missing annotation */
    00177 /*@only@*/ /*@out@*/ void * alloca (size_t __size)
    00178         /*@ensures maxSet(result) == (__size - 1) @*/
    00179         /*@*/;
    00180 /*@=declundef =incondefs @*/
    00181 #endif
    00182
    00183 #ifdef __GNUC__
    00184 # undef alloca
    00185 # define alloca __builtin_alloca
    00186 #else
    00187 # ifdef HAVE_ALLOCA_H
    00188 #  include <alloca.h>
    00189 # else
    00190 #  ifndef _AIX
    00191 /* AIX alloca decl has to be the first thing in the file, bletch! */
    00192 char *alloca ();
    00193 #  endif
    00194 # endif
    00195 #endif
    00196
    00197 #if defined (__GLIBC__) && defined(__LCLINT__)
    00198 /*@-declundef@*/
    00199 /*@unchecked@*/
    00200 extern __const __int32_t *__ctype_tolower;
    00201 /*@unchecked@*/
    00202 extern __const __int32_t *__ctype_toupper;
    00203 /*@=declundef@*/
    00204 #endif
    00205
    00206 #include <ctype.h>
    00207
    00208 #if defined (__GLIBC__) && defined(__LCLINT__)
    00209 /*@-exportlocal@*/
    00210 extern int isalnum(int) __THROW /*@*/;
    00211 extern int iscntrl(int) __THROW /*@*/;
    00212 extern int isgraph(int) __THROW /*@*/;
    00213 extern int islower(int) __THROW /*@*/;
    00214 extern int ispunct(int) __THROW /*@*/;
    00215 extern int isxdigit(int) __THROW        /*@*/;
    00216 extern int isascii(int) __THROW /*@*/;
    00217 extern int toascii(int) __THROW /*@*/;
    00218 extern int _toupper(int) __THROW        /*@*/;
    00219 extern int _tolower(int) __THROW        /*@*/;
    00220 /*@=exportlocal@*/
    00221
    00222 #endif
    00223
    00224 #if HAVE_SYS_MMAN_H && !defined(__LCLINT__)
    00225 #include <sys/mman.h>
    00226 #endif
    00227
    00228 /* XXX FIXME: popt on sunos4.1.3: <sys/resource.h> requires <sys/time.h> */
    00229 #if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
    00230 #include <sys/resource.h>
    00231 #endif
    00232
    00233 #if HAVE_SYS_UTSNAME_H
    00234 #include <sys/utsname.h>
    00235 #endif
    00236
    00237 #if HAVE_SYS_WAIT_H
    00238 #include <sys/wait.h>
    00239 #endif
    00240
    00241 #if HAVE_GETOPT_H
    00242 /*@-noparams@*/
    00243 #include <getopt.h>
    00244 /*@=noparams@*/
    00245 #endif
    00246
    00247 #if HAVE_GRP_H
    00248 #include <grp.h>
    00249 #endif
    00250
    00251 #if HAVE_LIMITS_H
    00252 #include <limits.h>
    00253 #endif
    00254
    00255 #if HAVE_ERR_H
    00256 #include <err.h>
    00257 #endif
    00258
    00259 #if HAVE_MALLOC_H && !defined(__LCLINT__)
    00260 #include <malloc.h>
    00261 #endif
    00262
    00263 /*@-declundef -incondefs @*/ /* FIX: these are macros */
    00266 /*@mayexit@*/ /*@only@*/ /*@out@*/ void * xmalloc (size_t size)
    00267         /*@globals errno @*/
    00268         /*@ensures maxSet(result) == (size - 1) @*/
    00269         /*@modifies errno @*/;
    00270
    00273 /*@mayexit@*/ /*@only@*/ void * xcalloc (size_t nmemb, size_t size)
    00274         /*@ensures maxSet(result) == (nmemb - 1) @*/
    00275         /*@*/;
    00276
    00280 /*@mayexit@*/ /*@only@*/ void * xrealloc (/*@null@*/ /*@only@*/ void * ptr,
    00281                                         size_t size)
    00282         /*@ensures maxSet(result) == (size - 1) @*/
    00283         /*@modifies *ptr @*/;
    00284
    00287 /*@mayexit@*/ /*@only@*/ char * xstrdup (const char *str)
    00288         /*@*/;
    00289 /*@=declundef =incondefs @*/
    00290
    00293 /*@unused@*/ /*@exits@*/ /*@only@*/ void * vmefail(size_t size)
    00294         /*@*/;
    00295
    00296 #if HAVE_MCHECK_H
    00297 #include <mcheck.h>
    00298 #if defined(__LCLINT__)
    00299 /*@-declundef -incondefs @*/ /* LCL: missing annotations */
    00300 #if 0
    00301 enum mcheck_status
    00302   {
    00303     MCHECK_DISABLED = -1,       /* Consistency checking is not turned on.  */
    00304     MCHECK_OK,                  /* Block is fine.  */
    00305     MCHECK_FREE,                /* Block freed twice.  */
    00306     MCHECK_HEAD,                /* Memory before the block was clobbered.  */
    00307     MCHECK_TAIL                 /* Memory after the block was clobbered.  */
    00308   };
    00309 #endif
    00310
    00311 extern int mcheck (void (*__abortfunc) (enum mcheck_status))
    00312         /*@globals internalState@*/
    00313         /*@modifies internalState @*/;
    00314 extern int mcheck_pedantic (void (*__abortfunc) (enum mcheck_status))
    00315         /*@globals internalState@*/
    00316         /*@modifies internalState @*/;
    00317 extern void mcheck_check_all (void)
    00318         /*@globals internalState@*/
    00319         /*@modifies internalState @*/;
    00320 extern enum mcheck_status mprobe (void *__ptr)
    00321         /*@globals internalState@*/
    00322         /*@modifies internalState @*/;
    00323 extern void mtrace (void)
    00324         /*@globals internalState@*/
    00325         /*@modifies internalState @*/;
    00326 extern void muntrace (void)
    00327         /*@globals internalState@*/
    00328         /*@modifies internalState @*/;
    00329 /*@=declundef =incondefs @*/
    00330 #endif /* defined(__LCLINT__) */
    00331
    00332 /* Memory allocation via macro defs to get meaningful locations from mtrace() */
    00333 #if defined(__GNUC__)
    00334 #define xmalloc(_size)          (malloc(_size) ? : vmefail(_size))
    00335 #define xcalloc(_nmemb, _size)  (calloc((_nmemb), (_size)) ? : vmefail(_size))
    00336 #define xrealloc(_ptr, _size)   (realloc((_ptr), (_size)) ? : vmefail(_size))
    00337 #define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail(strlen(_str)+1)), (_str)))
    00338 #endif  /* defined(__GNUC__) */
    00339 #endif  /* HAVE_MCHECK_H */
    00340
    00341 /* Retrofit glibc __progname */
    00342 #if defined __GLIBC__ && __GLIBC__ >= 2
    00343 #if __GLIBC_MINOR__ >= 1
    00344 #define __progname      __assert_program_name
    00345 #endif
    00346 #define setprogname(pn)
    00347 #else
    00348 #define __progname      program_name
    00349 #define setprogname(pn) \
    00350   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
    00351     else __progname = pn;               \
    00352   }
    00353 #endif
    00354 /*@unchecked@*/
    00355 const char *__progname;
    00356
    00357 #if HAVE_NETDB_H
    00358 #include <netdb.h>
    00359 #endif
    00360
    00361 #if HAVE_PWD_H
    00362 #include <pwd.h>
    00363 #endif
    00364
    00365 /* Take care of NLS matters.  */
    00366
    00367 #if HAVE_LOCALE_H
    00368 # include <locale.h>
    00369 #endif
    00370 #if !HAVE_SETLOCALE
    00371 # define setlocale(Category, Locale) /* empty */
    00372 #endif
    00373
    00374 #if ENABLE_NLS && !defined(__LCLINT__)
    00375 # include <libintl.h>
    00376 # define _(Text) gettext (Text)
    00377 #else
    00378 # undef bindtextdomain
    00379 # define bindtextdomain(Domain, Directory) /* empty */
    00380 # undef textdomain
    00381 # define textdomain(Domain) /* empty */
    00382 # define _(Text) Text
    00383 # undef dgettext
    00384 # define dgettext(DomainName, Text) Text
    00385 #endif
    00386
    00387 #define N_(Text) Text
    00388
    00389 /* ============== from misc/miscfn.h */
    00390
    00391 #if !defined(USE_GNU_GLOB)
    00392 #if HAVE_FNMATCH_H
    00393 /*@-noparams@*/
    00394 #include <fnmatch.h>
    00395 /*@=noparams@*/
    00396 #endif
    00397
    00398 #if HAVE_GLOB_H
    00399 /*@-noparams@*/
    00400 #include <glob.h>
    00401 /*@=noparams@*/
    00402 #endif
    00403 #else
    00404 /*@-noparams@*/
    00405 #include "misc/glob.h"
    00406 #include "misc/fnmatch.h"
    00407 /*@=noparams@*/
    00408 #endif
    00409
    00410 #if defined(__LCLINT__)
    00411 /*@-declundef -incondefs @*/ /* LCL: missing annotation */
    00412 #if 0
    00413 typedef /*@concrete@*/ struct
    00414   {
    00415     size_t gl_pathc;
    00416     char **gl_pathv;
    00417     size_t gl_offs;
    00418     int gl_flags;
    00419
    00420     void (*gl_closedir) (void *);
    00421 #ifdef _GNU_SOURCE
    00422     struct dirent *(*gl_readdir) (void *);
    00423 #else
    00424     void *(*gl_readdir) (void *);
    00425 #endif
    00426     ptr_t (*gl_opendir) (const char *);
    00427 #ifdef _GNU_SOURCE
    00428     int (*gl_lstat) (const char *restrict, struct stat *restrict);
    00429     int (*gl_stat) (const char *restrict, struct stat *restrict);
    00430 #else
    00431     int (*gl_lstat) (const char *restrict, void *restrict);
    00432     int (*gl_stat) (const char *restrict, void *restrict);
    00433 #endif
    00434   } glob_t;
    00435 #endif
    00436
    00437 #if 0
    00438 /*@-constuse@*/
    00439 /*@constant int GLOB_ERR@*/
    00440 /*@constant int GLOB_MARK@*/
    00441 /*@constant int GLOB_NOSORT@*/
    00442 /*@constant int GLOB_DOOFFS@*/
    00443 /*@constant int GLOB_NOCHECK@*/
    00444 /*@constant int GLOB_APPEND@*/
    00445 /*@constant int GLOB_NOESCAPE@*/
    00446 /*@constant int GLOB_PERIOD@*/
    00447
    00448 #ifdef _GNU_SOURCE
    00449 /*@constant int GLOB_MAGCHAR@*/
    00450 /*@constant int GLOB_ALTDIRFUNC@*/
    00451 /*@constant int GLOB_BRACE@*/
    00452 /*@constant int GLOB_NOMAGIC@*/
    00453 /*@constant int GLOB_TILDE@*/
    00454 /*@constant int GLOB_ONLYDIR@*/
    00455 /*@constant int GLOB_TILDE_CHECK@*/
    00456 #endif
    00457
    00458 /*@constant int GLOB_FLAGS@*/
    00459
    00460 /*@constant int GLOB_NOSPACE@*/
    00461 /*@constant int GLOB_ABORTED@*/
    00462 /*@constant int GLOB_NOMATCH@*/
    00463 /*@constant int GLOB_NOSYS@*/
    00464 #ifdef _GNU_SOURCE
    00465 /*@constant int GLOB_ABEND@*/
    00466 #endif
    00467 /*@=constuse@*/
    00468 #endif
    00469
    00470 extern int glob (const char *pattern, int flags,
    00471                       int (*errfunc) (const char *, int),
    00472                       /*@out@*/ glob_t *pglob)
    00473         /*@globals errno, fileSystem @*/
    00474         /*@modifies *pglob, errno, fileSystem @*/;
    00475         /* XXX only annotation is a white lie */
    00476 extern void globfree (/*@only@*/ glob_t *pglob)
    00477         /*@modifies *pglob @*/;
    00478 #ifdef _GNU_SOURCE
    00479 extern int glob_pattern_p (const char *pattern, int quote)
    00480         /*@*/;
    00481 #endif
    00482
    00483 #if 0
    00484 /*@-constuse@*/
    00485 /*@constant int FNM_PATHNAME@*/
    00486 /*@constant int FNM_NOESCAPE@*/
    00487 /*@constant int FNM_PERIOD@*/
    00488
    00489 #ifdef _GNU_SOURCE
    00490 /*@constant int FNM_FILE_NAME@*/        /* GNU extension */
    00491 /*@constant int FNM_LEADING_DIR@*/      /* GNU extension */
    00492 /*@constant int FNM_CASEFOLD@*/         /* GNU extension */
    00493 /*@constant int FNM_EXTMATCH@*/         /* GNU extension */
    00494 #endif
    00495
    00496 /*@constant int FNM_NOMATCH@*/
    00497
    00498 #ifdef _XOPEN_SOURCE
    00499 /*@constant int FNM_NOSYS@*/            /* X/Open */
    00500 #endif
    00501 /*@=constuse@*/
    00502 #endif
    00503
    00504 extern int fnmatch (const char *pattern, const char *string, int flags)
    00505         /*@*/;
    00506 /*@=declundef =incondefs @*/
    00507 #endif
    00508
    00509 #if ! HAVE_S_IFSOCK
    00510 #define S_IFSOCK (0xc000)
    00511 #endif
    00512
    00513 #if ! HAVE_S_ISLNK
    00514 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
    00515 #endif
    00516
    00517 #if ! HAVE_S_ISSOCK
    00518 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
    00519 #endif
    00520
    00521 #if NEED_STRINGS_H
    00522 #include <strings.h>
    00523 #endif
    00524
    00525 #if NEED_MYREALLOC
    00526 #define realloc(ptr,size) myrealloc(ptr,size)
    00527 extern void *myrealloc(void *, size_t);
    00528 #endif
    00529
    00530 #if ! HAVE_SETENV
    00531 extern int setenv(const char *name, const char *value, int replace);
    00532 extern void unsetenv(const char *name);
    00533 #endif
    00534
    00535 #if HAVE_SYS_SOCKET_H
    00536 #include <sys/types.h>
    00537 #include <sys/socket.h>
    00538 #endif
    00539
    00540 #if HAVE_SYS_SELECT_H && !defined(__LCLINT__)
    00541 #include <sys/select.h>
    00542 #endif
    00543
    00544 /* Solaris <= 2.6 limits getpass return to only 8 chars */
    00545 #if HAVE_GETPASSPHRASE
    00546 #define getpass getpassphrase
    00547 #endif
    00548
    00549 #if ! HAVE_LCHOWN
    00550 #define lchown chown
    00551 #endif
    00552
    00553 #if HAVE_GETMNTINFO_R || HAVE_MNTCTL
    00554 # define GETMNTENT_ONE 0
    00555 # define GETMNTENT_TWO 0
    00556 # if HAVE_SYS_MNTCTL_H
    00557 #  include <sys/mntctl.h>
    00558 # endif
    00559 # if HAVE_SYS_VMOUNT_H
    00560 #  include <sys/vmount.h>
    00561 # endif
    00562 # if HAVE_SYS_MOUNT_H
    00563 #  include <sys/mount.h>
    00564 # endif
    00565 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
    00566 # if HAVE_MNTENT_H
    00567 #  include <stdio.h>
    00568 #  include <mntent.h>
    00569 #  define our_mntent struct mntent
    00570 #  define our_mntdir mnt_dir
    00571 # elif HAVE_STRUCT_MNTTAB
    00572 #  include <stdio.h>
    00573 #  include <mnttab.h>
    00574    struct our_mntent {
    00575        char * our_mntdir;
    00576    };
    00577    struct our_mntent *getmntent(FILE *filep);
    00578 #  define our_mntent struct our_mntent
    00579 # else
    00580 #  include <stdio.h>
    00581    struct our_mntent {
    00582        char * our_mntdir;
    00583    };
    00584    struct our_mntent *getmntent(FILE *filep);
    00585 #  define our_mntent struct our_mntent
    00586 # endif
    00587 # define GETMNTENT_ONE 1
    00588 # define GETMNTENT_TWO 0
    00589 #elif HAVE_SYS_MNTTAB_H
    00590 # include <stdio.h>
    00591 # include <sys/mnttab.h>
    00592 # define GETMNTENT_ONE 0
    00593 # define GETMNTENT_TWO 1
    00594 # define our_mntent struct mnttab
    00595 # define our_mntdir mnt_mountp
    00596 #else /* if !HAVE_MNTCTL */
    00597 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
    00598 #endif
    00599
    00600 #ifndef MOUNTED
    00601 #define MOUNTED "/etc/mnttab"
    00602 #endif
    00603 #endif  /* H_SYSTEM */