- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

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