00001
00002
00003
00004
00005
00006 #if STAT_MACROS_BROKEN
00007 # undef S_ISBLK
00008 # undef S_ISCHR
00009 # undef S_ISDIR
00010 # undef S_ISDOOR
00011 # undef S_ISFIFO
00012 # undef S_ISLNK
00013 # undef S_ISMPB
00014 # undef S_ISMPC
00015 # undef S_ISNWK
00016 # undef S_ISREG
00017 # undef S_ISSOCK
00018 #endif
00019
00020 #ifndef S_IFMT
00021 # define S_IFMT 0170000
00022 #endif
00023 #if !defined(S_ISBLK) && defined(S_IFBLK)
00024 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
00025 #endif
00026 #if !defined(S_ISCHR) && defined(S_IFCHR)
00027 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
00028 #endif
00029 #if !defined(S_ISDIR) && defined(S_IFDIR)
00030 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
00031 #endif
00032 #if !defined(S_ISREG) && defined(S_IFREG)
00033 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
00034 #endif
00035 #if !defined(S_ISFIFO) && defined(S_IFIFO)
00036 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
00037 #endif
00038 #if !defined(S_ISLNK) && defined(S_IFLNK)
00039 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
00040 #endif
00041 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
00042 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
00043 #endif
00044 #if !defined(S_ISMPB) && defined(S_IFMPB)
00045 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
00046 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
00047 #endif
00048 #if !defined(S_ISNWK) && defined(S_IFNWK)
00049 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
00050 #endif
00051 #if !defined(S_ISDOOR) && defined(S_IFDOOR)
00052 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
00053 #endif
00054
00055 #if !S_ISUID
00056 # define S_ISUID 04000
00057 #endif
00058 #if !S_ISGID
00059 # define S_ISGID 02000
00060 #endif
00061
00062
00063 #ifndef S_ISVTX
00064 # define S_ISVTX 01000
00065 #endif
00066
00067 #if !S_IRUSR && S_IREAD
00068 # define S_IRUSR S_IREAD
00069 #endif
00070 #if !S_IRUSR
00071 # define S_IRUSR 00400
00072 #endif
00073 #if !S_IRGRP
00074 # define S_IRGRP (S_IRUSR >> 3)
00075 #endif
00076 #if !S_IROTH
00077 # define S_IROTH (S_IRUSR >> 6)
00078 #endif
00079
00080 #if !S_IWUSR && S_IWRITE
00081 # define S_IWUSR S_IWRITE
00082 #endif
00083 #if !S_IWUSR
00084 # define S_IWUSR 00200
00085 #endif
00086 #if !S_IWGRP
00087 # define S_IWGRP (S_IWUSR >> 3)
00088 #endif
00089 #if !S_IWOTH
00090 # define S_IWOTH (S_IWUSR >> 6)
00091 #endif
00092
00093 #if !S_IXUSR && S_IEXEC
00094 # define S_IXUSR S_IEXEC
00095 #endif
00096 #if !S_IXUSR
00097 # define S_IXUSR 00100
00098 #endif
00099 #if !S_IXGRP
00100 # define S_IXGRP (S_IXUSR >> 3)
00101 #endif
00102 #if !S_IXOTH
00103 # define S_IXOTH (S_IXUSR >> 6)
00104 #endif
00105
00106 #if !S_IRWXU
00107 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
00108 #endif
00109 #if !S_IRWXG
00110 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
00111 #endif
00112 #if !S_IRWXO
00113 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
00114 #endif
00115
00116
00117 #if !S_IXUGO
00118 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
00119 #endif
00120
00121 #ifndef S_IRWXUGO
00122 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
00123 #endif
00124
00125
00126 #define CHMOD_MODE_BITS \
00127 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
00128
00129 #ifdef ST_MTIM_NSEC
00130 # define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
00131 #else
00132 # define ST_TIME_CMP_NS(a, b, ns) 0
00133 #endif
00134 #define ST_TIME_CMP(a, b, s, ns) \
00135 ((a).s < (b).s ? -1 : (a).s > (b).s ? 1 : ST_TIME_CMP_NS(a, b, ns))
00136 #define ATIME_CMP(a, b) ST_TIME_CMP (a, b, st_atime, st_atim.ST_MTIM_NSEC)
00137 #define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
00138 #define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
00139
00140 #ifndef RETSIGTYPE
00141 # define RETSIGTYPE void
00142 #endif
00143
00144 #ifndef __GNUC__
00145 # if HAVE_ALLOCA_H
00146 # include <alloca.h>
00147 # else
00148 # ifdef _AIX
00149 # pragma alloca
00150 # else
00151 # ifdef _WIN32
00152 # include <malloc.h>
00153 # include <io.h>
00154 # else
00155 # ifndef alloca
00156 char *alloca ();
00157 # endif
00158 # endif
00159 # endif
00160 # endif
00161 #endif
00162
00163 #ifdef __DJGPP__
00164
00165 # include <io.h>
00166
00167 # include <sys/exceptn.h>
00168 #endif
00169
00170 #if HAVE_STDINT_H
00171 # include <stdint.h>
00172 #endif
00173
00174 #if HAVE_INTTYPES_H
00175 # include <inttypes.h>
00176 #endif
00177
00178 #include <ctype.h>
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
00200 # define IN_CTYPE_DOMAIN(c) 1
00201 #else
00202 # define IN_CTYPE_DOMAIN(c) isascii(c)
00203 #endif
00204
00205 #ifdef isblank
00206 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
00207 #else
00208 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
00209 #endif
00210 #ifdef isgraph
00211 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
00212 #else
00213 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
00214 #endif
00215
00216
00217 #undef ISPRINT
00218
00219 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
00220 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
00221 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
00222 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
00223 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
00224 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
00225 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
00226 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
00227 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
00228 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
00229
00230 #if STDC_HEADERS
00231 # define TOLOWER(Ch) tolower (Ch)
00232 # define TOUPPER(Ch) toupper (Ch)
00233 #else
00234 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
00235 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
00236 #endif
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
00247
00248 #ifndef PARAMS
00249 # if PROTOTYPES
00250 # define PARAMS(Args) Args
00251 # else
00252 # define PARAMS(Args) ()
00253 # endif
00254 #endif
00255
00256
00257
00258 #if HAVE_LOCALE_H
00259 # include <locale.h>
00260 #endif
00261 #if !HAVE_SETLOCALE
00262 # define setlocale(Category, Locale)
00263 #endif
00264
00265 #if ENABLE_NLS
00266 # include <libintl.h>
00267 # if HAVE_GETTEXT && !HAVE_DCGETTEXT && !defined dcgettext
00268 # define dcgettext(Domain, Text, Category) Text
00269 # endif
00270 # define _(Text) gettext (Text)
00271 #else
00272 # undef bindtextdomain
00273 # define bindtextdomain(Domain, Directory)
00274 # undef textdomain
00275 # define textdomain(Domain)
00276 # undef dcgettext
00277 # define dcgettext(Domainname, Text, Category) Text
00278 # define _(Text) Text
00279 #endif
00280 #define N_(Text) Text
00281
00282 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
00283
00284 #if !HAVE_DECL_FREE
00285 void free ();
00286 #endif
00287
00288 #if !HAVE_DECL_MALLOC
00289 char *malloc ();
00290 #endif
00291
00292 #if !HAVE_DECL_MEMCHR
00293 char *memchr ();
00294 #endif
00295
00296 #if !HAVE_DECL_REALLOC
00297 char *realloc ();
00298 #endif
00299
00300 #if !HAVE_DECL_STPCPY
00301 # ifndef stpcpy
00302 char *stpcpy ();
00303 # endif
00304 #endif
00305
00306 #if !HAVE_DECL_STRNDUP
00307 char *strndup ();
00308 #endif
00309
00310 #if !HAVE_DECL_STRSTR
00311 char *strstr ();
00312 #endif
00313
00314 #if !HAVE_DECL_GETENV
00315 char *getenv ();
00316 #endif
00317
00318 #if !HAVE_DECL_LSEEK
00319 off_t lseek ();
00320 #endif
00321
00322
00323 #if !HAVE_DECL_STRTOUL
00324 unsigned long strtoul ();
00325 #endif
00326
00327
00328 #if !HAVE_DECL_STRTOULL && HAVE_UNSIGNED_LONG_LONG
00329 unsigned long long strtoull ();
00330 #endif
00331
00332 #if !HAVE_DECL_GETLOGIN
00333 char *getlogin ();
00334 #endif
00335
00336 #if !HAVE_DECL_TTYNAME
00337 char *ttyname ();
00338 #endif
00339
00340 #if !HAVE_DECL_GETEUID
00341 uid_t geteuid ();
00342 #endif
00343
00344 #if !HAVE_DECL_GETPWUID
00345 struct passwd *getpwuid ();
00346 #endif
00347
00348 #if !HAVE_DECL_GETGRGID
00349 struct group *getgrgid ();
00350 #endif
00351
00352 #if !HAVE_DECL_GETUID
00353 uid_t getuid ();
00354 #endif
00355
00356 #include "xalloc.h"
00357
00358 #if ! defined HAVE_MEMPCPY && ! defined mempcpy
00359
00360 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
00361 #endif
00362
00363
00364
00365
00366
00367
00368 #if HAVE_CLEARERR_UNLOCKED
00369 # undef clearerr
00370 # define clearerr(S) clearerr_unlocked (S)
00371 #endif
00372
00373 #if HAVE_FEOF_UNLOCKED
00374 # undef feof
00375 # define feof(S) feof_unlocked (S)
00376 #endif
00377
00378 #if HAVE_FERROR_UNLOCKED
00379 # undef ferror
00380 # define ferror(S) ferror_unlocked (S)
00381 #endif
00382
00383 #if HAVE_FFLUSH_UNLOCKED
00384 # undef fflush
00385 # define fflush(S) fflush_unlocked (S)
00386 #endif
00387
00388 #if HAVE_FPUTC_UNLOCKED
00389 # undef fputc
00390 # define fputc(C, S) fputc_unlocked (C, S)
00391 #endif
00392
00393 #if HAVE_FREAD_UNLOCKED
00394 # undef fread
00395 # define fread(P, Z, N, S) fread_unlocked (P, Z, N, S)
00396 #endif
00397
00398 #if HAVE_FWRITE_UNLOCKED
00399 # undef fwrite
00400 # define fwrite(P, Z, N, S) fwrite_unlocked (P, Z, N, S)
00401 #endif
00402
00403 #if HAVE_GETC_UNLOCKED
00404 # undef getc
00405 # define getc(S) getc_unlocked (S)
00406 #endif
00407
00408 #if HAVE_GETCHAR_UNLOCKED
00409 # undef getchar
00410 # define getchar(S) getchar_unlocked (S)
00411 #endif
00412
00413 #if HAVE_PUTC_UNLOCKED
00414 # undef putc
00415 # define putc(C, S) putc_unlocked (C, S)
00416 #endif
00417
00418 #if HAVE_PUTCHAR_UNLOCKED
00419 # undef putchar
00420 # define putchar(C) putchar_unlocked (C)
00421 #endif
00422
00423 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
00424 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
00425 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
00426
00427 #define DOT_OR_DOTDOT(Basename) \
00428 (Basename[0] == '.' && (Basename[1] == '\0' \
00429 || (Basename[1] == '.' && Basename[2] == '\0')))
00430
00431 #if SETVBUF_REVERSED
00432 # define SETVBUF(Stream, Buffer, Type, Size) \
00433 setvbuf (Stream, Type, Buffer, Size)
00434 #else
00435 # define SETVBUF(Stream, Buffer, Type, Size) \
00436 setvbuf (Stream, Buffer, Type, Size)
00437 #endif
00438
00439 char *base_name PARAMS ((char const *));
00440
00441
00442
00443
00444
00445
00446 enum
00447 {
00448 GETOPT_HELP_CHAR = (CHAR_MIN - 2),
00449 GETOPT_VERSION_CHAR = (CHAR_MIN - 3)
00450 };
00451
00452 #define GETOPT_HELP_OPTION_DECL \
00453 "help", no_argument, 0, GETOPT_HELP_CHAR
00454 #define GETOPT_VERSION_OPTION_DECL \
00455 "version", no_argument, 0, GETOPT_VERSION_CHAR
00456
00457 #define case_GETOPT_HELP_CHAR \
00458 case GETOPT_HELP_CHAR: \
00459 usage (EXIT_SUCCESS); \
00460 break;
00461
00462 #include "closeout.h"
00463 #include "version-etc.h"
00464
00465 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
00466 case GETOPT_VERSION_CHAR: \
00467 version_etc (stdout, Program_name, PACKAGE, VERSION, Authors); \
00468 exit (EXIT_SUCCESS); \
00469 break;
00470
00471 #ifndef MAX
00472 # define MAX(a, b) ((a) > (b) ? (a) : (b))
00473 #endif
00474
00475 #ifndef MIN
00476 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
00477 #endif
00478
00479 #ifndef CHAR_BIT
00480 # define CHAR_BIT 8
00481 #endif
00482
00483
00484 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
00485
00486
00487 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
00488 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
00489 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
00490
00491
00492
00493
00494 #define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
00495
00496 #ifndef CHAR_MIN
00497 # define CHAR_MIN TYPE_MINIMUM (char)
00498 #endif
00499
00500 #ifndef CHAR_MAX
00501 # define CHAR_MAX TYPE_MAXIMUM (char)
00502 #endif
00503
00504 #ifndef SCHAR_MIN
00505 # define SCHAR_MIN (-1 - SCHAR_MAX)
00506 #endif
00507
00508 #ifndef SCHAR_MAX
00509 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
00510 #endif
00511
00512 #ifndef UCHAR_MAX
00513 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
00514 #endif
00515
00516 #ifndef SHRT_MIN
00517 # define SHRT_MIN TYPE_MINIMUM (short int)
00518 #endif
00519
00520 #ifndef SHRT_MAX
00521 # define SHRT_MAX TYPE_MAXIMUM (short int)
00522 #endif
00523
00524 #ifndef INT_MAX
00525 # define INT_MAX TYPE_MAXIMUM (int)
00526 #endif
00527
00528 #ifndef UINT_MAX
00529 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
00530 #endif
00531
00532 #ifndef LONG_MAX
00533 # define LONG_MAX TYPE_MAXIMUM (long)
00534 #endif
00535
00536 #ifndef ULONG_MAX
00537 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
00538 #endif
00539
00540 #ifndef SIZE_MAX
00541 # define SIZE_MAX TYPE_MAXIMUM (size_t)
00542 #endif
00543
00544 #ifndef UINTMAX_MAX
00545 # define UINTMAX_MAX TYPE_MAXIMUM (uintmax_t)
00546 #endif
00547
00548 #ifndef OFF_T_MIN
00549 # define OFF_T_MIN TYPE_MINIMUM (off_t)
00550 #endif
00551
00552 #ifndef OFF_T_MAX
00553 # define OFF_T_MAX TYPE_MAXIMUM (off_t)
00554 #endif
00555
00556 #ifndef UID_T_MAX
00557 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
00558 #endif
00559
00560 #ifndef GID_T_MAX
00561 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
00562 #endif
00563
00564 #ifndef PID_T_MAX
00565 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
00566 #endif
00567
00568 #ifndef CHAR_BIT
00569 # define CHAR_BIT 8
00570 #endif
00571
00572
00573 #ifdef lint
00574 # define IF_LINT(Code) Code
00575 #else
00576 # define IF_LINT(Code)
00577 #endif
00578
00579 #ifndef __attribute__
00580 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
00581 # define __attribute__(x)
00582 # endif
00583 #endif
00584
00585 #ifndef ATTRIBUTE_NORETURN
00586 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
00587 #endif
00588
00589 #ifndef ATTRIBUTE_UNUSED
00590 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
00591 #endif
00592
00593 #if defined strdupa
00594 # define ASSIGN_STRDUPA(DEST, S) \
00595 do { DEST = strdupa(S); } while (0)
00596 #else
00597 # define ASSIGN_STRDUPA(DEST, S) \
00598 do \
00599 { \
00600 const char *s_ = (S); \
00601 size_t len_ = strlen (s_) + 1; \
00602 char *tmp_dest_ = (char *) alloca (len_); \
00603 DEST = memcpy (tmp_dest_, (s_), len_); \
00604 } \
00605 while (0)
00606 #endif