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 RETSIGTYPE void
30 /* We need the declaration of setmode. */
32 /* We need the declaration of __djgpp_set_ctrl_c. */
33 # include <sys/exceptn.h>
38 /* Jim Meyering writes:
40 "... Some ctype macros are valid only for character codes that
41 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
42 using /bin/cc or gcc but without giving an ansi option). So, all
43 ctype uses should be through macros like ISPRINT... If
44 STDC_HEADERS is defined, then autoconf has verified that the ctype
45 macros don't need to be guarded with references to isascii. ...
46 Defining isascii to 1 should let any compiler worth its salt
47 eliminate the && through constant folding."
51 "... Furthermore, isupper(c) etc. have an undefined result if c is
52 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
53 with c being of type `char', but this is wrong if c is an 8-bit
54 character >= 128 which gets sign-extended to a negative value.
55 The macro ISUPPER protects against this as well." */
57 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
58 # define IN_CTYPE_DOMAIN(c) 1
60 # define IN_CTYPE_DOMAIN(c) isascii(c)
64 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
66 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
69 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
71 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
74 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
75 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
76 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
77 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
78 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
79 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
80 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
81 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
82 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
83 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
86 # define TOLOWER(Ch) tolower (Ch)
87 # define TOUPPER(Ch) toupper (Ch)
89 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
90 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
93 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
94 - Its arg may be any int or unsigned int; it need not be an unsigned char.
95 - It's guaranteed to evaluate its argument exactly once.
96 - It's typically faster.
97 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
98 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
99 it's important to use the locale's definition of `digit' even when the
100 host does not conform to Posix. */
101 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
105 # define PARAMS(Args) Args
107 # define PARAMS(Args) ()
111 /* Take care of NLS matters. */
117 # define setlocale(Category, Locale) /* empty */
121 # include <libintl.h>
122 # define _(Text) gettext (Text)
124 # undef bindtextdomain
125 # define bindtextdomain(Domain, Directory) /* empty */
127 # define textdomain(Domain) /* empty */
128 # define _(Text) Text
130 #define N_(Text) Text
132 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
134 #ifndef HAVE_DECL_FREE
138 #ifndef HAVE_DECL_MALLOC
142 #ifndef HAVE_DECL_MEMCHR
146 #ifndef HAVE_DECL_REALLOC
150 #ifndef HAVE_DECL_STPCPY
156 #ifndef HAVE_DECL_STRSTR
160 #ifndef HAVE_DECL_GETENV
164 #ifndef HAVE_DECL_LSEEK
170 #if ! defined HAVE_MEMPCPY && ! defined mempcpy
171 /* Be CAREFUL that there are no side effects in N. */
172 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
175 /* These are wrappers for functions/macros from GNU libc.
176 The standard I/O functions are thread-safe. These *_unlocked ones
177 are more efficient but not thread-safe. That they're not thread-safe
178 is fine since all these applications are single threaded. */
180 #ifdef HAVE_CLEARERR_UNLOCKED
182 # define clearerr(S) clearerr_unlocked (S)
185 #ifdef HAVE_FEOF_UNLOCKED
187 # define feof(S) feof_unlocked (S)
190 #ifdef HAVE_FERROR_UNLOCKED
192 # define ferror(S) ferror_unlocked (S)
195 #ifdef HAVE_FFLUSH_UNLOCKED
197 # define fflush(S) fflush_unlocked (S)
200 #ifdef HAVE_FPUTC_UNLOCKED
202 # define fputc(C, S) fputc_unlocked (C, S)
205 #ifdef HAVE_FREAD_UNLOCKED
207 # define fread(P, Z, N, S) fread_unlocked (P, Z, N, S)
210 #ifdef HAVE_FWRITE_UNLOCKED
212 # define fwrite(P, Z, N, S) fwrite_unlocked (P, Z, N, S)
215 #ifdef HAVE_GETC_UNLOCKED
217 # define getc(S) getc_unlocked (S)
220 #ifdef HAVE_GETCHAR_UNLOCKED
222 # define getchar(S) getchar_unlocked (S)
225 #ifdef HAVE_PUTC_UNLOCKED
227 # define putc(C, S) putc_unlocked (C, S)
230 #ifdef HAVE_PUTCHAR_UNLOCKED
232 # define putchar(C) putchar_unlocked (C)
235 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
236 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
237 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
239 #define DOT_OR_DOTDOT(Basename) \
240 (Basename[0] == '.' && (Basename[1] == '\0' \
241 || (Basename[1] == '.' && Basename[2] == '\0')))
244 # define SETVBUF(Stream, Buffer, Type, Size) \
245 setvbuf (Stream, Type, Buffer, Size)
247 # define SETVBUF(Stream, Buffer, Type, Size) \
248 setvbuf (Stream, Buffer, Type, Size)
251 char *base_name
PARAMS ((char const *));
253 /* Factor out some of the common --help and --version processing code. */
255 #define GETOPT_HELP_CHAR 250
256 #define GETOPT_VERSION_CHAR 251
258 #define GETOPT_HELP_OPTION_DECL \
259 "help", no_argument, 0, GETOPT_HELP_CHAR
260 #define GETOPT_VERSION_OPTION_DECL \
261 "version", no_argument, 0, GETOPT_VERSION_CHAR
263 #define case_GETOPT_HELP_CHAR \
264 case GETOPT_HELP_CHAR: \
265 usage (EXIT_SUCCESS); \
268 #include "closeout.h"
269 #include "version-etc.h"
271 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
272 case GETOPT_VERSION_CHAR: \
273 version_etc (stdout, Program_name, GNU_PACKAGE, VERSION, Authors); \
275 exit (EXIT_SUCCESS); \
279 # define MAX(a, b) ((a) > (b) ? (a) : (b))
283 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
290 /* The extra casts work around common compiler bugs. */
291 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
292 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
293 It is necessary at least when t == time_t. */
294 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
295 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
296 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
299 # define CHAR_MIN TYPE_MINIMUM (char)
303 # define CHAR_MAX TYPE_MAXIMUM (char)
307 # define SCHAR_MIN (-1 - SCHAR_MAX)
311 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
315 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
319 # define SHRT_MIN TYPE_MINIMUM (short int)
323 # define SHRT_MAX TYPE_MAXIMUM (short int)
327 # define INT_MAX TYPE_MAXIMUM (int)
331 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
335 # define LONG_MAX TYPE_MAXIMUM (long)
339 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
343 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
347 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
351 # define PID_T_MAX TYPE_MAXIMUM (pid_t)