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)
121 /* All the mode bits that can be affected by chmod. */
122 #define CHMOD_MODE_BITS \
123 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
126 # define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
128 # define ST_TIME_CMP_NS(a, b, ns) 0
130 #define ST_TIME_CMP(a, b, s, ns) \
131 ((a).s < (b).s ? -1 : (a).s > (b).s ? 1 : ST_TIME_CMP_NS(a, b, ns))
132 #define ATIME_CMP(a, b) ST_TIME_CMP (a, b, st_atime, st_atim.ST_MTIM_NSEC)
133 #define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
134 #define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
137 # define RETSIGTYPE void
160 /* We need the declaration of setmode. */
162 /* We need the declaration of __djgpp_set_ctrl_c. */
163 # include <sys/exceptn.h>
168 /* Jim Meyering writes:
170 "... Some ctype macros are valid only for character codes that
171 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
172 using /bin/cc or gcc but without giving an ansi option). So, all
173 ctype uses should be through macros like ISPRINT... If
174 STDC_HEADERS is defined, then autoconf has verified that the ctype
175 macros don't need to be guarded with references to isascii. ...
176 Defining isascii to 1 should let any compiler worth its salt
177 eliminate the && through constant folding."
181 "... Furthermore, isupper(c) etc. have an undefined result if c is
182 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
183 with c being of type `char', but this is wrong if c is an 8-bit
184 character >= 128 which gets sign-extended to a negative value.
185 The macro ISUPPER protects against this as well." */
187 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
188 # define IN_CTYPE_DOMAIN(c) 1
190 # define IN_CTYPE_DOMAIN(c) isascii(c)
194 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
196 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
199 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
201 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
204 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
205 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
206 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
207 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
208 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
209 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
210 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
211 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
212 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
213 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
216 # define TOLOWER(Ch) tolower (Ch)
217 # define TOUPPER(Ch) toupper (Ch)
219 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
220 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
223 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
224 - Its arg may be any int or unsigned int; it need not be an unsigned char.
225 - It's guaranteed to evaluate its argument exactly once.
226 - It's typically faster.
227 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
228 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
229 it's important to use the locale's definition of `digit' even when the
230 host does not conform to Posix. */
231 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
235 # define PARAMS(Args) Args
237 # define PARAMS(Args) ()
241 /* Take care of NLS matters. */
247 # define setlocale(Category, Locale) /* empty */
251 # include <libintl.h>
252 # define _(Text) gettext (Text)
254 # undef bindtextdomain
255 # define bindtextdomain(Domain, Directory) /* empty */
257 # define textdomain(Domain) /* empty */
258 # define _(Text) Text
260 #define N_(Text) Text
262 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
264 #ifndef HAVE_DECL_FREE
268 #ifndef HAVE_DECL_MALLOC
272 #ifndef HAVE_DECL_MEMCHR
276 #ifndef HAVE_DECL_REALLOC
280 #ifndef HAVE_DECL_STPCPY
286 #ifndef HAVE_DECL_STRSTR
290 #ifndef HAVE_DECL_GETENV
294 #ifndef HAVE_DECL_LSEEK
300 #if ! defined HAVE_MEMPCPY && ! defined mempcpy
301 /* Be CAREFUL that there are no side effects in N. */
302 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
305 /* These are wrappers for functions/macros from GNU libc.
306 The standard I/O functions are thread-safe. These *_unlocked ones
307 are more efficient but not thread-safe. That they're not thread-safe
308 is fine since all these applications are single threaded. */
310 #if HAVE_CLEARERR_UNLOCKED
312 # define clearerr(S) clearerr_unlocked (S)
315 #if HAVE_FEOF_UNLOCKED
317 # define feof(S) feof_unlocked (S)
320 #if HAVE_FERROR_UNLOCKED
322 # define ferror(S) ferror_unlocked (S)
325 #if HAVE_FFLUSH_UNLOCKED
327 # define fflush(S) fflush_unlocked (S)
330 #if HAVE_FPUTC_UNLOCKED
332 # define fputc(C, S) fputc_unlocked (C, S)
335 #if HAVE_FREAD_UNLOCKED
337 # define fread(P, Z, N, S) fread_unlocked (P, Z, N, S)
340 #if HAVE_FWRITE_UNLOCKED
342 # define fwrite(P, Z, N, S) fwrite_unlocked (P, Z, N, S)
345 #if HAVE_GETC_UNLOCKED
347 # define getc(S) getc_unlocked (S)
350 #if HAVE_GETCHAR_UNLOCKED
352 # define getchar(S) getchar_unlocked (S)
355 #if HAVE_PUTC_UNLOCKED
357 # define putc(C, S) putc_unlocked (C, S)
360 #if HAVE_PUTCHAR_UNLOCKED
362 # define putchar(C) putchar_unlocked (C)
365 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
366 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
367 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
369 #define DOT_OR_DOTDOT(Basename) \
370 (Basename[0] == '.' && (Basename[1] == '\0' \
371 || (Basename[1] == '.' && Basename[2] == '\0')))
374 # define SETVBUF(Stream, Buffer, Type, Size) \
375 setvbuf (Stream, Type, Buffer, Size)
377 # define SETVBUF(Stream, Buffer, Type, Size) \
378 setvbuf (Stream, Buffer, Type, Size)
381 char *base_name
PARAMS ((char const *));
383 /* Factor out some of the common --help and --version processing code. */
385 #define GETOPT_HELP_CHAR 250
386 #define GETOPT_VERSION_CHAR 251
388 #define GETOPT_HELP_OPTION_DECL \
389 "help", no_argument, 0, GETOPT_HELP_CHAR
390 #define GETOPT_VERSION_OPTION_DECL \
391 "version", no_argument, 0, GETOPT_VERSION_CHAR
393 #define case_GETOPT_HELP_CHAR \
394 case GETOPT_HELP_CHAR: \
395 usage (EXIT_SUCCESS); \
398 #include "closeout.h"
399 #include "version-etc.h"
401 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
402 case GETOPT_VERSION_CHAR: \
403 version_etc (stdout, Program_name, GNU_PACKAGE, VERSION, Authors); \
405 exit (EXIT_SUCCESS); \
409 # define MAX(a, b) ((a) > (b) ? (a) : (b))
413 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
420 /* The extra casts work around common compiler bugs. */
421 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
422 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
423 It is necessary at least when t == time_t. */
424 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
425 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
426 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
429 # define CHAR_MIN TYPE_MINIMUM (char)
433 # define CHAR_MAX TYPE_MAXIMUM (char)
437 # define SCHAR_MIN (-1 - SCHAR_MAX)
441 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
445 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
449 # define SHRT_MIN TYPE_MINIMUM (short int)
453 # define SHRT_MAX TYPE_MAXIMUM (short int)
457 # define INT_MAX TYPE_MAXIMUM (int)
461 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
465 # define LONG_MAX TYPE_MAXIMUM (long)
469 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
473 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
477 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
481 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
484 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
486 # define IF_LINT(Code) Code
488 # define IF_LINT(Code) /* empty */
491 #ifndef __attribute__
492 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
493 # define __attribute__(x)
497 #ifndef ATTRIBUTE_NORETURN
498 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
501 #ifndef ATTRIBUTE_UNUSED
502 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))