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. */
7 # define S_IFMT 0170000
10 #if STAT_MACROS_BROKEN
28 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
36 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
44 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
50 #ifndef S_ISDOOR /* Solaris 2.5 and up */
52 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
54 # define S_ISDOOR(m) 0
60 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
62 # define S_ISFIFO(m) 0
68 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
74 #ifndef S_ISMPB /* V7 */
76 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
77 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
84 #ifndef S_ISNAM /* Xenix */
86 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
92 #ifndef S_ISNWK /* HP/UX */
94 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
102 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
104 # define S_ISREG(m) 0
110 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
112 # define S_ISSOCK(m) 0
119 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
121 # define S_TYPEISSEM(p) 0
127 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
129 # define S_TYPEISSHM(p) 0
134 # define S_TYPEISMQ(p) 0
138 /* If any of the following are undefined,
139 define them to their de facto standard values. */
141 # define S_ISUID 04000
144 # define S_ISGID 02000
147 /* S_ISVTX is a common extension to POSIX. */
149 # define S_ISVTX 01000
152 #if !S_IRUSR && S_IREAD
153 # define S_IRUSR S_IREAD
156 # define S_IRUSR 00400
159 # define S_IRGRP (S_IRUSR >> 3)
162 # define S_IROTH (S_IRUSR >> 6)
165 #if !S_IWUSR && S_IWRITE
166 # define S_IWUSR S_IWRITE
169 # define S_IWUSR 00200
172 # define S_IWGRP (S_IWUSR >> 3)
175 # define S_IWOTH (S_IWUSR >> 6)
178 #if !S_IXUSR && S_IEXEC
179 # define S_IXUSR S_IEXEC
182 # define S_IXUSR 00100
185 # define S_IXGRP (S_IXUSR >> 3)
188 # define S_IXOTH (S_IXUSR >> 6)
192 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
195 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
198 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
201 /* S_IXUGO is a common extension to POSIX. */
203 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
207 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
210 /* All the mode bits that can be affected by chmod. */
211 #define CHMOD_MODE_BITS \
212 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
215 # define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
217 # define ST_TIME_CMP_NS(a, b, ns) 0
219 #define ST_TIME_CMP(a, b, s, ns) \
220 ((a).s < (b).s ? -1 : (a).s > (b).s ? 1 : ST_TIME_CMP_NS(a, b, ns))
221 #define ATIME_CMP(a, b) ST_TIME_CMP (a, b, st_atime, st_atim.ST_MTIM_NSEC)
222 #define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
223 #define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
226 # define RETSIGTYPE void
231 # define alloca __builtin_alloca
253 /* We need the declaration of setmode. */
255 /* We need the declaration of __djgpp_set_ctrl_c. */
256 # include <sys/exceptn.h>
264 # include <inttypes.h> /* for the definition of UINTMAX_MAX */
269 /* Jim Meyering writes:
271 "... Some ctype macros are valid only for character codes that
272 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
273 using /bin/cc or gcc but without giving an ansi option). So, all
274 ctype uses should be through macros like ISPRINT... If
275 STDC_HEADERS is defined, then autoconf has verified that the ctype
276 macros don't need to be guarded with references to isascii. ...
277 Defining isascii to 1 should let any compiler worth its salt
278 eliminate the && through constant folding."
282 "... Furthermore, isupper(c) etc. have an undefined result if c is
283 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
284 with c being of type `char', but this is wrong if c is an 8-bit
285 character >= 128 which gets sign-extended to a negative value.
286 The macro ISUPPER protects against this as well." */
288 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
289 # define IN_CTYPE_DOMAIN(c) 1
291 # define IN_CTYPE_DOMAIN(c) isascii(c)
295 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
297 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
300 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
302 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
305 /* This is defined in <sys/euc.h> on at least Solaris2.6 systems. */
308 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
309 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
310 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
311 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
312 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
313 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
314 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
315 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
316 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
317 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
320 # define TOLOWER(Ch) tolower (Ch)
321 # define TOUPPER(Ch) toupper (Ch)
323 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
324 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
327 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
328 - Its arg may be any int or unsigned int; it need not be an unsigned char.
329 - It's guaranteed to evaluate its argument exactly once.
330 - It's typically faster.
331 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
332 ISDIGIT_LOCALE unless it's important to use the locale's definition
333 of `digit' even when the host does not conform to POSIX. */
334 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
338 # define PARAMS(Args) Args
340 # define PARAMS(Args) ()
344 /* Take care of NLS matters. */
349 # define setlocale(Category, Locale) /* empty */
354 #define _(msgid) gettext (msgid)
355 #define N_(msgid) msgid
357 #ifndef HAVE_SETLOCALE
358 # define HAVE_SETLOCALE 0
361 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
367 #if !HAVE_DECL_MALLOC
371 #if !HAVE_DECL_MEMCHR
375 #if !HAVE_DECL_REALLOC
379 #if !HAVE_DECL_STPCPY
385 #if !HAVE_DECL_STRNDUP
389 #if !HAVE_DECL_STRSTR
393 #if !HAVE_DECL_GETENV
401 /* This is needed on some AIX systems. */
402 #if !HAVE_DECL_STRTOUL
403 unsigned long strtoul ();
406 /* This is needed on some AIX systems. */
407 #if !HAVE_DECL_STRTOULL && HAVE_UNSIGNED_LONG_LONG
408 unsigned long long strtoull ();
411 #if !HAVE_DECL_GETLOGIN
415 #if !HAVE_DECL_TTYNAME
419 #if !HAVE_DECL_GETEUID
423 #if !HAVE_DECL_GETPWUID
424 struct passwd
*getpwuid ();
427 #if !HAVE_DECL_GETGRGID
428 struct group
*getgrgid ();
431 #if !HAVE_DECL_GETUID
437 #if ! defined HAVE_MEMPCPY && ! defined mempcpy
438 /* Be CAREFUL that there are no side effects in N. */
439 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
442 /* Include automatically-generated macros for unlocked I/O. */
443 #include "unlocked-io.h"
445 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
446 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
447 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
449 #define DOT_OR_DOTDOT(Basename) \
450 (Basename[0] == '.' && (Basename[1] == '\0' \
451 || (Basename[1] == '.' && Basename[2] == '\0')))
454 # define SETVBUF(Stream, Buffer, Type, Size) \
455 setvbuf (Stream, Type, Buffer, Size)
457 # define SETVBUF(Stream, Buffer, Type, Size) \
458 setvbuf (Stream, Buffer, Type, Size)
461 /* Factor out some of the common --help and --version processing code. */
463 /* These enum values cannot possibly conflict with the option values
464 ordinarily used by commands, including CHAR_MAX + 1, etc. Avoid
465 CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value. */
468 GETOPT_HELP_CHAR
= (CHAR_MIN
- 2),
469 GETOPT_VERSION_CHAR
= (CHAR_MIN
- 3)
472 #define GETOPT_HELP_OPTION_DECL \
473 "help", no_argument, 0, GETOPT_HELP_CHAR
474 #define GETOPT_VERSION_OPTION_DECL \
475 "version", no_argument, 0, GETOPT_VERSION_CHAR
477 #define case_GETOPT_HELP_CHAR \
478 case GETOPT_HELP_CHAR: \
479 usage (EXIT_SUCCESS); \
482 #define HELP_OPTION_DESCRIPTION \
483 _(" --help display this help and exit\n")
484 #define VERSION_OPTION_DESCRIPTION \
485 _(" --version output version information and exit\n")
487 #include "closeout.h"
488 #include "version-etc.h"
490 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
491 case GETOPT_VERSION_CHAR: \
492 version_etc (stdout, Program_name, PACKAGE, VERSION, Authors); \
493 exit (EXIT_SUCCESS); \
497 # define MAX(a, b) ((a) > (b) ? (a) : (b))
501 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
508 /* The extra casts work around common compiler bugs. */
509 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
510 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
511 It is necessary at least when t == time_t. */
512 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
513 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
514 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
516 /* Upper bound on the string length of an integer converted to string.
517 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
518 add 1 for integer division truncation; add 1 more for a minus sign. */
519 #define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
522 # define CHAR_MIN TYPE_MINIMUM (char)
526 # define CHAR_MAX TYPE_MAXIMUM (char)
530 # define SCHAR_MIN (-1 - SCHAR_MAX)
534 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
538 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
542 # define SHRT_MIN TYPE_MINIMUM (short int)
546 # define SHRT_MAX TYPE_MAXIMUM (short int)
550 # define INT_MAX TYPE_MAXIMUM (int)
554 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
558 # define LONG_MAX TYPE_MAXIMUM (long)
562 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
566 # define SIZE_MAX TYPE_MAXIMUM (size_t)
570 # define UINTMAX_MAX TYPE_MAXIMUM (uintmax_t)
574 # define OFF_T_MIN TYPE_MINIMUM (off_t)
578 # define OFF_T_MAX TYPE_MAXIMUM (off_t)
582 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
586 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
590 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
597 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
599 # define IF_LINT(Code) Code
601 # define IF_LINT(Code) /* empty */
604 #ifndef __attribute__
605 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
606 # define __attribute__(x)
610 #ifndef ATTRIBUTE_NORETURN
611 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
614 #ifndef ATTRIBUTE_UNUSED
615 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
619 # define ASSIGN_STRDUPA(DEST, S) \
620 do { DEST = strdupa(S); } while (0)
622 # define ASSIGN_STRDUPA(DEST, S) \
625 const char *s_ = (S); \
626 size_t len_ = strlen (s_) + 1; \
627 char *tmp_dest_ = (char *) alloca (len_); \
628 DEST = memcpy (tmp_dest_, (s_), len_); \
634 # define EOVERFLOW EINVAL
637 #if ! HAVE_FSEEKO && ! defined fseeko
638 # define fseeko(s, o, w) ((o) == (long) (o) \
640 : (errno = EOVERFLOW, -1))