1 /* WARNING -- this file is temporary. It is shared between the
2 sh-utils, fileutils, and textutils packages. Once I find a little
3 more time, I'll merge the remaining things in system.h and everything
4 in this file will go back there. */
18 #endif /* STAT_MACROS_BROKEN. */
21 # define S_IFMT 0170000
23 #if !defined(S_ISBLK) && defined(S_IFBLK)
24 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
26 #if !defined(S_ISCHR) && defined(S_IFCHR)
27 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
29 #if !defined(S_ISDIR) && defined(S_IFDIR)
30 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
32 #if !defined(S_ISREG) && defined(S_IFREG)
33 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
35 #if !defined(S_ISFIFO) && defined(S_IFIFO)
36 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
38 #if !defined(S_ISLNK) && defined(S_IFLNK)
39 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
41 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
42 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
44 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
45 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
46 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
48 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
49 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
51 #if !defined(S_ISDOOR) && defined(S_IFDOOR) /* Solaris 2.5 and up */
52 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
56 # define S_ISUID 04000
59 # define S_ISGID 02000
62 /* S_ISVTX is a common extension to POSIX.1. */
64 # define S_ISVTX 01000
67 #if !S_IRUSR && S_IREAD
68 # define S_IRUSR S_IREAD
71 # define S_IRUSR 00400
74 # define S_IRGRP (S_IRUSR >> 3)
77 # define S_IROTH (S_IRUSR >> 6)
80 #if !S_IWUSR && S_IWRITE
81 # define S_IWUSR S_IWRITE
84 # define S_IWUSR 00200
87 # define S_IWGRP (S_IWUSR >> 3)
90 # define S_IWOTH (S_IWUSR >> 6)
93 #if !S_IXUSR && S_IEXEC
94 # define S_IXUSR S_IEXEC
97 # define S_IXUSR 00100
100 # define S_IXGRP (S_IXUSR >> 3)
103 # define S_IXOTH (S_IXUSR >> 6)
107 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
110 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
113 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
116 /* S_IXUGO is a common extension to POSIX.1. */
118 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
122 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
125 /* All the mode bits that can be affected by chmod. */
126 #define CHMOD_MODE_BITS \
127 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
130 # define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
132 # define ST_TIME_CMP_NS(a, b, ns) 0
134 #define ST_TIME_CMP(a, b, s, ns) \
135 ((a).s < (b).s ? -1 : (a).s > (b).s ? 1 : ST_TIME_CMP_NS(a, b, ns))
136 #define ATIME_CMP(a, b) ST_TIME_CMP (a, b, st_atime, st_atim.ST_MTIM_NSEC)
137 #define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
138 #define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
141 # define RETSIGTYPE void
164 /* We need the declaration of setmode. */
166 /* We need the declaration of __djgpp_set_ctrl_c. */
167 # include <sys/exceptn.h>
175 # include <inttypes.h> /* for the definition of UINTMAX_MAX */
180 /* Jim Meyering writes:
182 "... Some ctype macros are valid only for character codes that
183 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
184 using /bin/cc or gcc but without giving an ansi option). So, all
185 ctype uses should be through macros like ISPRINT... If
186 STDC_HEADERS is defined, then autoconf has verified that the ctype
187 macros don't need to be guarded with references to isascii. ...
188 Defining isascii to 1 should let any compiler worth its salt
189 eliminate the && through constant folding."
193 "... Furthermore, isupper(c) etc. have an undefined result if c is
194 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
195 with c being of type `char', but this is wrong if c is an 8-bit
196 character >= 128 which gets sign-extended to a negative value.
197 The macro ISUPPER protects against this as well." */
199 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
200 # define IN_CTYPE_DOMAIN(c) 1
202 # define IN_CTYPE_DOMAIN(c) isascii(c)
206 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
208 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
211 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
213 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
216 /* This is defined in <sys/euc.h> on at least Solaris2.6 systems. */
219 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
220 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
221 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
222 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
223 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
224 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
225 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
226 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
227 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
228 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
231 # define TOLOWER(Ch) tolower (Ch)
232 # define TOUPPER(Ch) toupper (Ch)
234 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
235 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
238 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
239 - Its arg may be any int or unsigned int; it need not be an unsigned char.
240 - It's guaranteed to evaluate its argument exactly once.
241 - It's typically faster.
242 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
243 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
244 it's important to use the locale's definition of `digit' even when the
245 host does not conform to Posix. */
246 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
250 # define PARAMS(Args) Args
252 # define PARAMS(Args) ()
256 /* Take care of NLS matters. */
262 # define setlocale(Category, Locale) /* empty */
266 # include <libintl.h>
267 # if HAVE_GETTEXT && !HAVE_DCGETTEXT && !defined dcgettext
268 # define dcgettext(Domain, Text, Category) Text
270 # define _(Text) gettext (Text)
272 # undef bindtextdomain
273 # define bindtextdomain(Domain, Directory) /* empty */
275 # define textdomain(Domain) /* empty */
277 # define dcgettext(Domainname, Text, Category) Text
278 # define _(Text) Text
280 #define N_(Text) Text
282 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
288 #if !HAVE_DECL_MALLOC
292 #if !HAVE_DECL_MEMCHR
296 #if !HAVE_DECL_REALLOC
300 #if !HAVE_DECL_STPCPY
306 #if !HAVE_DECL_STRNDUP
310 #if !HAVE_DECL_STRSTR
314 #if !HAVE_DECL_GETENV
322 /* This is needed on some AIX systems. */
323 #if !HAVE_DECL_STRTOUL
324 unsigned long strtoul ();
327 /* This is needed on some AIX systems. */
328 #if !HAVE_DECL_STRTOULL && HAVE_UNSIGNED_LONG_LONG
329 unsigned long long strtoull ();
332 #if !HAVE_DECL_GETLOGIN
336 #if !HAVE_DECL_TTYNAME
340 #if !HAVE_DECL_GETEUID
344 #if !HAVE_DECL_GETPWUID
345 struct passwd
*getpwuid ();
348 #if !HAVE_DECL_GETGRGID
349 struct group
*getgrgid ();
352 #if !HAVE_DECL_GETUID
358 #if ! defined HAVE_MEMPCPY && ! defined mempcpy
359 /* Be CAREFUL that there are no side effects in N. */
360 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
363 /* These are wrappers for functions/macros from GNU libc.
364 The standard I/O functions are thread-safe. These *_unlocked ones
365 are more efficient but not thread-safe. That they're not thread-safe
366 is fine since all these applications are single threaded. */
368 #if HAVE_CLEARERR_UNLOCKED
370 # define clearerr(S) clearerr_unlocked (S)
373 #if HAVE_FEOF_UNLOCKED
375 # define feof(S) feof_unlocked (S)
378 #if HAVE_FERROR_UNLOCKED
380 # define ferror(S) ferror_unlocked (S)
383 #if HAVE_FFLUSH_UNLOCKED
385 # define fflush(S) fflush_unlocked (S)
388 #if HAVE_FPUTC_UNLOCKED
390 # define fputc(C, S) fputc_unlocked (C, S)
393 #if HAVE_FREAD_UNLOCKED
395 # define fread(P, Z, N, S) fread_unlocked (P, Z, N, S)
398 #if HAVE_FWRITE_UNLOCKED
400 # define fwrite(P, Z, N, S) fwrite_unlocked (P, Z, N, S)
403 #if HAVE_GETC_UNLOCKED
405 # define getc(S) getc_unlocked (S)
408 #if HAVE_GETCHAR_UNLOCKED
410 # define getchar(S) getchar_unlocked (S)
413 #if HAVE_PUTC_UNLOCKED
415 # define putc(C, S) putc_unlocked (C, S)
418 #if HAVE_PUTCHAR_UNLOCKED
420 # define putchar(C) putchar_unlocked (C)
423 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
424 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
425 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
427 #define DOT_OR_DOTDOT(Basename) \
428 (Basename[0] == '.' && (Basename[1] == '\0' \
429 || (Basename[1] == '.' && Basename[2] == '\0')))
432 # define SETVBUF(Stream, Buffer, Type, Size) \
433 setvbuf (Stream, Type, Buffer, Size)
435 # define SETVBUF(Stream, Buffer, Type, Size) \
436 setvbuf (Stream, Buffer, Type, Size)
439 char *base_name
PARAMS ((char const *));
441 /* Factor out some of the common --help and --version processing code. */
443 /* These enum values cannot possibly conflict with the option values
444 ordinarily used by commands, including CHAR_MAX + 1, etc. Avoid
445 CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value. */
448 GETOPT_HELP_CHAR
= (CHAR_MIN
- 2),
449 GETOPT_VERSION_CHAR
= (CHAR_MIN
- 3)
452 #define GETOPT_HELP_OPTION_DECL \
453 "help", no_argument, 0, GETOPT_HELP_CHAR
454 #define GETOPT_VERSION_OPTION_DECL \
455 "version", no_argument, 0, GETOPT_VERSION_CHAR
457 #define case_GETOPT_HELP_CHAR \
458 case GETOPT_HELP_CHAR: \
459 usage (EXIT_SUCCESS); \
462 #include "closeout.h"
463 #include "version-etc.h"
465 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
466 case GETOPT_VERSION_CHAR: \
467 version_etc (stdout, Program_name, PACKAGE, VERSION, Authors); \
468 exit (EXIT_SUCCESS); \
472 # define MAX(a, b) ((a) > (b) ? (a) : (b))
476 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
483 /* The extra casts work around common compiler bugs. */
484 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
485 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
486 It is necessary at least when t == time_t. */
487 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
488 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
489 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
491 /* Upper bound on the string length of an integer converted to string.
492 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
493 add 1 for integer division truncation; add 1 more for a minus sign. */
494 #define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
497 # define CHAR_MIN TYPE_MINIMUM (char)
501 # define CHAR_MAX TYPE_MAXIMUM (char)
505 # define SCHAR_MIN (-1 - SCHAR_MAX)
509 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
513 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
517 # define SHRT_MIN TYPE_MINIMUM (short int)
521 # define SHRT_MAX TYPE_MAXIMUM (short int)
525 # define INT_MAX TYPE_MAXIMUM (int)
529 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
533 # define LONG_MAX TYPE_MAXIMUM (long)
537 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
541 # define SIZE_MAX TYPE_MAXIMUM (size_t)
545 # define UINTMAX_MAX TYPE_MAXIMUM (uintmax_t)
549 # define OFF_T_MIN TYPE_MINIMUM (off_t)
553 # define OFF_T_MAX TYPE_MAXIMUM (off_t)
557 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
561 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
565 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
572 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
574 # define IF_LINT(Code) Code
576 # define IF_LINT(Code) /* empty */
579 #ifndef __attribute__
580 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
581 # define __attribute__(x)
585 #ifndef ATTRIBUTE_NORETURN
586 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
589 #ifndef ATTRIBUTE_UNUSED
590 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
594 # define ASSIGN_STRDUPA(DEST, S) \
595 do { DEST = strdupa(S); } while (0)
597 # define ASSIGN_STRDUPA(DEST, S) \
600 const char *s_ = (S); \
601 size_t len_ = strlen (s_) + 1; \
602 char *tmp_dest_ = (char *) alloca (len_); \
603 DEST = memcpy (tmp_dest_, (s_), len_); \