(do_link): Produce the same sort of one-line output for
[coreutils.git] / src / sys2.h
blobc9af9f02accf266580ca265bd81ba6a195b6a39a
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. */
6 #if STAT_MACROS_BROKEN
7 # undef S_ISBLK
8 # undef S_ISCHR
9 # undef S_ISDIR
10 # undef S_ISDOOR
11 # undef S_ISFIFO
12 # undef S_ISLNK
13 # undef S_ISMPB
14 # undef S_ISMPC
15 # undef S_ISNWK
16 # undef S_ISREG
17 # undef S_ISSOCK
18 #endif /* STAT_MACROS_BROKEN. */
20 #ifndef S_IFMT
21 # define S_IFMT 0170000
22 #endif
23 #if !defined(S_ISBLK) && defined(S_IFBLK)
24 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
25 #endif
26 #if !defined(S_ISCHR) && defined(S_IFCHR)
27 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
28 #endif
29 #if !defined(S_ISDIR) && defined(S_IFDIR)
30 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
31 #endif
32 #if !defined(S_ISREG) && defined(S_IFREG)
33 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
34 #endif
35 #if !defined(S_ISFIFO) && defined(S_IFIFO)
36 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
37 #endif
38 #if !defined(S_ISLNK) && defined(S_IFLNK)
39 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
40 #endif
41 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
42 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
43 #endif
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)
47 #endif
48 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
49 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
50 #endif
51 #if !defined(S_ISDOOR) && defined(S_IFDOOR) /* Solaris 2.5 and up */
52 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
53 #endif
55 #if !S_ISUID
56 # define S_ISUID 04000
57 #endif
58 #if !S_ISGID
59 # define S_ISGID 02000
60 #endif
62 /* S_ISVTX is a common extension to POSIX.1. */
63 #ifndef S_ISVTX
64 # define S_ISVTX 01000
65 #endif
67 #if !S_IRUSR && S_IREAD
68 # define S_IRUSR S_IREAD
69 #endif
70 #if !S_IRUSR
71 # define S_IRUSR 00400
72 #endif
73 #if !S_IRGRP
74 # define S_IRGRP (S_IRUSR >> 3)
75 #endif
76 #if !S_IROTH
77 # define S_IROTH (S_IRUSR >> 6)
78 #endif
80 #if !S_IWUSR && S_IWRITE
81 # define S_IWUSR S_IWRITE
82 #endif
83 #if !S_IWUSR
84 # define S_IWUSR 00200
85 #endif
86 #if !S_IWGRP
87 # define S_IWGRP (S_IWUSR >> 3)
88 #endif
89 #if !S_IWOTH
90 # define S_IWOTH (S_IWUSR >> 6)
91 #endif
93 #if !S_IXUSR && S_IEXEC
94 # define S_IXUSR S_IEXEC
95 #endif
96 #if !S_IXUSR
97 # define S_IXUSR 00100
98 #endif
99 #if !S_IXGRP
100 # define S_IXGRP (S_IXUSR >> 3)
101 #endif
102 #if !S_IXOTH
103 # define S_IXOTH (S_IXUSR >> 6)
104 #endif
106 #if !S_IRWXU
107 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
108 #endif
109 #if !S_IRWXG
110 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
111 #endif
112 #if !S_IRWXO
113 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
114 #endif
116 /* S_IXUGO is a common extension to POSIX.1. */
117 #if !S_IXUGO
118 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
119 #endif
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)
125 #if ST_MTIM_NSEC
126 # define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
127 #else
128 # define ST_TIME_CMP_NS(a, b, ns) 0
129 #endif
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)
136 #ifndef RETSIGTYPE
137 # define RETSIGTYPE void
138 #endif
140 #ifndef __GNUC__
141 # if HAVE_ALLOCA_H
142 # include <alloca.h>
143 # else
144 # ifdef _AIX
145 # pragma alloca
146 # else
147 # ifdef _WIN32
148 # include <malloc.h>
149 # include <io.h>
150 # else
151 # ifndef alloca
152 char *alloca ();
153 # endif
154 # endif
155 # endif
156 # endif
157 #endif
159 #ifdef __DJGPP__
160 /* We need the declaration of setmode. */
161 # include <io.h>
162 /* We need the declaration of __djgpp_set_ctrl_c. */
163 # include <sys/exceptn.h>
164 #endif
166 #include <ctype.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."
179 Bruno Haible adds:
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
189 #else
190 # define IN_CTYPE_DOMAIN(c) isascii(c)
191 #endif
193 #ifdef isblank
194 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
195 #else
196 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
197 #endif
198 #ifdef isgraph
199 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
200 #else
201 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
202 #endif
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))
215 #if STDC_HEADERS
216 # define TOLOWER(Ch) tolower (Ch)
217 # define TOUPPER(Ch) toupper (Ch)
218 #else
219 # define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
220 # define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
221 #endif
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)
233 #ifndef PARAMS
234 # if PROTOTYPES
235 # define PARAMS(Args) Args
236 # else
237 # define PARAMS(Args) ()
238 # endif
239 #endif
241 /* Take care of NLS matters. */
243 #if HAVE_LOCALE_H
244 # include <locale.h>
245 #endif
246 #if !HAVE_SETLOCALE
247 # define setlocale(Category, Locale) /* empty */
248 #endif
250 #if ENABLE_NLS
251 # include <libintl.h>
252 # define _(Text) gettext (Text)
253 #else
254 # undef bindtextdomain
255 # define bindtextdomain(Domain, Directory) /* empty */
256 # undef textdomain
257 # define textdomain(Domain) /* empty */
258 # define _(Text) Text
259 #endif
260 #define N_(Text) Text
262 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
264 #ifndef HAVE_DECL_FREE
265 void free ();
266 #endif
268 #ifndef HAVE_DECL_MALLOC
269 char *malloc ();
270 #endif
272 #ifndef HAVE_DECL_MEMCHR
273 char *memchr ();
274 #endif
276 #ifndef HAVE_DECL_REALLOC
277 char *realloc ();
278 #endif
280 #ifndef HAVE_DECL_STPCPY
281 # ifndef stpcpy
282 char *stpcpy ();
283 # endif
284 #endif
286 #ifndef HAVE_DECL_STRSTR
287 char *strstr ();
288 #endif
290 #ifndef HAVE_DECL_GETENV
291 char *getenv ();
292 #endif
294 #ifndef HAVE_DECL_LSEEK
295 off_t lseek ();
296 #endif
298 #include "xalloc.h"
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)))
303 #endif
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
311 # undef clearerr
312 # define clearerr(S) clearerr_unlocked (S)
313 #endif
315 #if HAVE_FEOF_UNLOCKED
316 # undef feof
317 # define feof(S) feof_unlocked (S)
318 #endif
320 #if HAVE_FERROR_UNLOCKED
321 # undef ferror
322 # define ferror(S) ferror_unlocked (S)
323 #endif
325 #if HAVE_FFLUSH_UNLOCKED
326 # undef fflush
327 # define fflush(S) fflush_unlocked (S)
328 #endif
330 #if HAVE_FPUTC_UNLOCKED
331 # undef fputc
332 # define fputc(C, S) fputc_unlocked (C, S)
333 #endif
335 #if HAVE_FREAD_UNLOCKED
336 # undef fread
337 # define fread(P, Z, N, S) fread_unlocked (P, Z, N, S)
338 #endif
340 #if HAVE_FWRITE_UNLOCKED
341 # undef fwrite
342 # define fwrite(P, Z, N, S) fwrite_unlocked (P, Z, N, S)
343 #endif
345 #if HAVE_GETC_UNLOCKED
346 # undef getc
347 # define getc(S) getc_unlocked (S)
348 #endif
350 #if HAVE_GETCHAR_UNLOCKED
351 # undef getchar
352 # define getchar(S) getchar_unlocked (S)
353 #endif
355 #if HAVE_PUTC_UNLOCKED
356 # undef putc
357 # define putc(C, S) putc_unlocked (C, S)
358 #endif
360 #if HAVE_PUTCHAR_UNLOCKED
361 # undef putchar
362 # define putchar(C) putchar_unlocked (C)
363 #endif
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')))
373 #if SETVBUF_REVERSED
374 # define SETVBUF(Stream, Buffer, Type, Size) \
375 setvbuf (Stream, Type, Buffer, Size)
376 #else
377 # define SETVBUF(Stream, Buffer, Type, Size) \
378 setvbuf (Stream, Buffer, Type, Size)
379 #endif
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); \
396 break;
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); \
404 close_stdout (); \
405 exit (EXIT_SUCCESS); \
406 break;
408 #ifndef MAX
409 # define MAX(a, b) ((a) > (b) ? (a) : (b))
410 #endif
412 #ifndef MIN
413 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
414 #endif
416 #ifndef CHAR_BIT
417 # define CHAR_BIT 8
418 #endif
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)))
428 #ifndef CHAR_MIN
429 # define CHAR_MIN TYPE_MINIMUM (char)
430 #endif
432 #ifndef CHAR_MAX
433 # define CHAR_MAX TYPE_MAXIMUM (char)
434 #endif
436 #ifndef SCHAR_MIN
437 # define SCHAR_MIN (-1 - SCHAR_MAX)
438 #endif
440 #ifndef SCHAR_MAX
441 # define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
442 #endif
444 #ifndef UCHAR_MAX
445 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
446 #endif
448 #ifndef SHRT_MIN
449 # define SHRT_MIN TYPE_MINIMUM (short int)
450 #endif
452 #ifndef SHRT_MAX
453 # define SHRT_MAX TYPE_MAXIMUM (short int)
454 #endif
456 #ifndef INT_MAX
457 # define INT_MAX TYPE_MAXIMUM (int)
458 #endif
460 #ifndef UINT_MAX
461 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
462 #endif
464 #ifndef LONG_MAX
465 # define LONG_MAX TYPE_MAXIMUM (long)
466 #endif
468 #ifndef ULONG_MAX
469 # define ULONG_MAX TYPE_MAXIMUM (unsigned long)
470 #endif
472 #ifndef UID_T_MAX
473 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
474 #endif
476 #ifndef GID_T_MAX
477 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
478 #endif
480 #ifndef PID_T_MAX
481 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
482 #endif
484 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
485 #ifdef lint
486 # define IF_LINT(Code) Code
487 #else
488 # define IF_LINT(Code) /* empty */
489 #endif
491 #ifndef __attribute__
492 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
493 # define __attribute__(x)
494 # endif
495 #endif
497 #ifndef ATTRIBUTE_NORETURN
498 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
499 #endif
501 #ifndef ATTRIBUTE_UNUSED
502 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
503 #endif