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
230 /* We need the declaration of setmode. */
232 /* We need the declaration of __djgpp_set_ctrl_c. */
233 # include <sys/exceptn.h>
241 # include <inttypes.h> /* for the definition of UINTMAX_MAX */
244 #if !defined PRIdMAX || PRI_MACROS_BROKEN
246 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
248 #if !defined PRIoMAX || PRI_MACROS_BROKEN
250 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
252 #if !defined PRIuMAX || PRI_MACROS_BROKEN
254 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
256 #if !defined PRIxMAX || PRI_MACROS_BROKEN
258 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
263 /* Jim Meyering writes:
265 "... Some ctype macros are valid only for character codes that
266 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
267 using /bin/cc or gcc but without giving an ansi option). So, all
268 ctype uses should be through macros like ISPRINT... If
269 STDC_HEADERS is defined, then autoconf has verified that the ctype
270 macros don't need to be guarded with references to isascii. ...
271 Defining isascii to 1 should let any compiler worth its salt
272 eliminate the && through constant folding."
276 "... Furthermore, isupper(c) etc. have an undefined result if c is
277 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
278 with c being of type `char', but this is wrong if c is an 8-bit
279 character >= 128 which gets sign-extended to a negative value.
280 The macro ISUPPER protects against this as well." */
282 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
283 # define IN_CTYPE_DOMAIN(c) 1
285 # define IN_CTYPE_DOMAIN(c) isascii(c)
289 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
291 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
294 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
296 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
299 /* This is defined in <sys/euc.h> on at least Solaris2.6 systems. */
302 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
303 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
304 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
305 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
306 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
307 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
308 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
309 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
310 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
311 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
314 # define TOLOWER(Ch) tolower (Ch)
315 # define TOUPPER(Ch) toupper (Ch)
317 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
318 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
321 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
322 - Its arg may be any int or unsigned int; it need not be an unsigned char.
323 - It's guaranteed to evaluate its argument exactly once.
324 - It's typically faster.
325 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
326 ISDIGIT_LOCALE unless it's important to use the locale's definition
327 of `digit' even when the host does not conform to POSIX. */
328 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
330 /* Take care of NLS matters. */
335 # define setlocale(Category, Locale) /* empty */
341 # define textdomain(Domainname) /* empty */
342 # undef bindtextdomain
343 # define bindtextdomain(Domainname, Dirname) /* empty */
346 #define _(msgid) gettext (msgid)
347 #define N_(msgid) msgid
349 #ifndef HAVE_SETLOCALE
350 # define HAVE_SETLOCALE 0
353 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
359 #if !HAVE_DECL_MALLOC
363 #if !HAVE_DECL_MEMCHR
367 #if !HAVE_DECL_REALLOC
371 #if !HAVE_DECL_STPCPY
377 #if !HAVE_DECL_STRNDUP
381 #if !HAVE_DECL_STRSTR
385 #if !HAVE_DECL_GETENV
393 /* This is needed on some AIX systems. */
394 #if !HAVE_DECL_STRTOUL
395 unsigned long strtoul ();
398 #if !HAVE_DECL_GETLOGIN
402 #if !HAVE_DECL_TTYNAME
406 #if !HAVE_DECL_GETEUID
410 #if !HAVE_DECL_GETPWUID
411 struct passwd *getpwuid ();
414 #if !HAVE_DECL_GETGRGID
415 struct group *getgrgid ();
418 #if !HAVE_DECL_GETUID
424 #if ! defined HAVE_MEMPCPY && ! defined mempcpy
425 /* Be CAREFUL that there are no side effects in N. */
426 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
429 /* Include automatically-generated macros for unlocked I/O. */
430 #include "unlocked-io.h"
432 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
433 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
434 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
436 #define DOT_OR_DOTDOT(Basename) \
437 (Basename[0] == '.' && (Basename[1] == '\0' \
438 || (Basename[1] == '.' && Basename[2] == '\0')))
441 # define SETVBUF(Stream, Buffer, Type, Size) \
442 setvbuf (Stream, Type, Buffer, Size)
444 # define SETVBUF(Stream, Buffer, Type, Size) \
445 setvbuf (Stream, Buffer, Type, Size)
448 /* Factor out some of the common --help and --version processing code. */
450 /* These enum values cannot possibly conflict with the option values
451 ordinarily used by commands, including CHAR_MAX + 1, etc. Avoid
452 CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value. */
455 GETOPT_HELP_CHAR = (CHAR_MIN - 2),
456 GETOPT_VERSION_CHAR = (CHAR_MIN - 3)
459 #define GETOPT_HELP_OPTION_DECL \
460 "help", no_argument, 0, GETOPT_HELP_CHAR
461 #define GETOPT_VERSION_OPTION_DECL \
462 "version", no_argument, 0, GETOPT_VERSION_CHAR
464 #define case_GETOPT_HELP_CHAR \
465 case GETOPT_HELP_CHAR: \
466 usage (EXIT_SUCCESS); \
469 #define HELP_OPTION_DESCRIPTION \
470 _(" --help display this help and exit\n")
471 #define VERSION_OPTION_DESCRIPTION \
472 _(" --version output version information and exit\n")
474 #include "closeout.h"
475 #include "version-etc.h"
477 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
478 case GETOPT_VERSION_CHAR: \
479 version_etc (stdout, Program_name, PACKAGE, VERSION, Authors, NULL);\
480 exit (EXIT_SUCCESS); \
484 # define MAX(a, b) ((a) > (b) ? (a) : (b))
488 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
495 /* The extra casts work around common compiler bugs. */
496 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
497 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
498 It is necessary at least when t == time_t. */
499 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
500 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
501 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
503 /* Upper bound on the string length of an integer converted to string.
504 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
505 add 1 for integer division truncation; add 1 more for a minus sign. */
506 #define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
509 # define CHAR_MIN TYPE_MINIMUM (char)
513 # define CHAR_MAX TYPE_MAXIMUM (char)
517 # define SCHAR_MIN (-1 - SCHAR_MAX)
521 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
525 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
529 # define SHRT_MIN TYPE_MINIMUM (short int)
533 # define SHRT_MAX TYPE_MAXIMUM (short int)
537 # define INT_MAX TYPE_MAXIMUM (int)
541 # define INT_MIN TYPE_MINIMUM (int)
545 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
549 # define LONG_MAX TYPE_MAXIMUM (long)
553 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
557 # define SIZE_MAX TYPE_MAXIMUM (size_t)
561 # define SSIZE_MAX TYPE_MAXIMUM (ssize_t)
565 # define UINTMAX_MAX TYPE_MAXIMUM (uintmax_t)
569 # define OFF_T_MIN TYPE_MINIMUM (off_t)
573 # define OFF_T_MAX TYPE_MAXIMUM (off_t)
577 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
581 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
585 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
588 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
590 # define IF_LINT(Code) Code
592 # define IF_LINT(Code) /* empty */
595 #ifndef __attribute__
596 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
597 # define __attribute__(x)
601 #ifndef ATTRIBUTE_NORETURN
602 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
605 #ifndef ATTRIBUTE_UNUSED
606 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
610 # define ASSIGN_STRDUPA(DEST, S) \
611 do { DEST = strdupa (S); } while (0)
613 # define ASSIGN_STRDUPA(DEST, S) \
616 const char *s_ = (S); \
617 size_t len_ = strlen (s_) + 1; \
618 char *tmp_dest_ = alloca (len_); \
619 DEST = memcpy (tmp_dest_, (s_), len_); \
625 # define EOVERFLOW EINVAL
628 #if ! HAVE_FSEEKO && ! defined fseeko
629 # define fseeko(s, o, w) ((o) == (long) (o) \
631 : (errno = EOVERFLOW, -1))