1 /* System dependent definitions for GNU tar.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* Declare alloca. AIX requires this to be the first thing in the file. */
28 # define alloca __builtin_alloca
44 /* This feature is available in gcc versions 2.5 and later. */
45 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
46 # define __attribute__(Spec) /* empty */
50 #include <sys/types.h>
57 # define offsetof(type, ident) ((size_t) &((type *) 0)->ident)
60 /* IN_CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
61 as an argument to <ctype.h> macros like `isspace'. */
63 # define IN_CTYPE_DOMAIN(c) 1
65 # define IN_CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
68 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
69 #define ISODIGIT(c) ((unsigned) (c) - '0' <= 7)
70 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
71 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
73 /* Declare string and memory handling routines. Take care that an ANSI
74 string.h and pre-ANSI memory.h might conflict, and that memory.h and
75 strings.h conflict on some systems. */
77 #if STDC_HEADERS || HAVE_STRING_H
79 # if !STDC_HEADERS && HAVE_MEMORY_H
88 # define strrchr rindex
91 # define memcpy(d, s, n) bcopy ((char const *) (s), (char *) (d), n)
94 # define memcmp(a, b, n) bcmp ((char const *) (a), (char const *) (b), n)
105 /* Declare open parameters. */
110 # include <sys/file.h>
112 /* Pick only one of the next three: */
114 # define O_RDONLY 0 /* only allow read */
117 # define O_WRONLY 1 /* only allow write */
120 # define O_RDWR 2 /* both are allowed */
123 # define O_ACCMODE (O_RDONLY | O_RDWR | O_WRONLY)
125 /* The rest can be OR-ed in to the above: */
127 # define O_CREAT 8 /* create file if needed */
130 # define O_EXCL 16 /* file cannot already exist */
133 # define O_TRUNC 32 /* truncate file on open */
135 /* MS-DOG forever, with my love! */
140 /* Declare file status routines and bits. */
142 #include <sys/stat.h>
144 #if !HAVE_LSTAT && !defined lstat
148 #if STX_HIDDEN && !_LARGE_FILES /* AIX */
152 # define stat(path, buf) statx (path, buf, STATSIZE, STX_HIDDEN)
156 # define lstat(path, buf) statx (path, buf, STATSIZE, STX_HIDDEN | STX_LINK)
159 #if STAT_MACROS_BROKEN
170 /* On MSDOS, there are missing things from <sys/stat.h>. */
178 # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
181 # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
186 # define S_ISBLK(Mode) (((Mode) & S_IFMT) == S_IFBLK)
188 # define S_ISBLK(Mode) 0
193 # define S_ISCHR(Mode) (((Mode) & S_IFMT) == S_IFCHR)
195 # define S_ISCHR(Mode) 0
200 # define S_ISCTG(Mode) (((Mode) & S_IFMT) == S_IFCTG)
202 # define S_ISCTG(Mode) 0
206 # define S_ISDOOR(Mode) 0
210 # define S_ISFIFO(Mode) (((Mode) & S_IFMT) == S_IFIFO)
212 # define S_ISFIFO(Mode) 0
217 # define S_ISLNK(Mode) (((Mode) & S_IFMT) == S_IFLNK)
219 # define S_ISLNK(Mode) 0
224 # define S_ISSOCK(Mode) (((Mode) & S_IFMT) == S_IFSOCK)
226 # define S_ISSOCK(Mode) 0
230 #if !HAVE_MKFIFO && !defined mkfifo && defined S_IFIFO
231 # define mkfifo(Path, Mode) (mknod (Path, (Mode) | S_IFIFO, 0))
235 # define S_ISUID 0004000
238 # define S_ISGID 0002000
241 # define S_ISVTX 0001000
244 # define S_IRUSR 0000400
247 # define S_IWUSR 0000200
250 # define S_IXUSR 0000100
253 # define S_IRGRP 0000040
256 # define S_IWGRP 0000020
259 # define S_IXGRP 0000010
262 # define S_IROTH 0000004
265 # define S_IWOTH 0000002
268 # define S_IXOTH 0000001
271 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
272 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
273 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
274 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
275 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
277 #ifndef _POSIX_SOURCE
278 # include <sys/param.h>
281 /* Include <unistd.h> before any preprocessor test of _POSIX_VERSION. */
297 # define STDIN_FILENO 0
299 #ifndef STDOUT_FILENO
300 # define STDOUT_FILENO 1
302 #ifndef STDERR_FILENO
303 # define STDERR_FILENO 2
306 /* Declare make device, major and minor. Since major is a function on
307 SVR4, we have to resort to GOT_MAJOR instead of just testing if
308 major is #define'd. */
311 # include <sys/mkdev.h>
315 #if MAJOR_IN_SYSMACROS
316 # include <sys/sysmacros.h>
320 /* Some <sys/types.h> defines the macros. */
327 # define major(Device) (Device)
328 # define minor(Device) (Device)
329 # define makedev(Major, Minor) (((Major) << 8) | (Minor))
334 /* For HP-UX before HP-UX 8, major/minor are not in <sys/sysmacros.h>. */
336 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
337 # include <sys/mknod.h>
343 # define major(Device) (((Device) >> 8) & 0xff)
344 # define minor(Device) ((Device) & 0xff)
345 # define makedev(Major, Minor) (((Major) << 8) | (Minor))
350 /* Declare wait status. */
353 # include <sys/wait.h>
356 # define WEXITSTATUS(s) (((s) >> 8) & 0xff)
359 # define WIFSIGNALED(s) (((s) & 0xffff) - 1 < (unsigned) 0xff)
362 # define WTERMSIG(s) ((s) & 0x7f)
365 /* FIXME: It is wrong to use BLOCKSIZE for buffers when the logical block
366 size is greater than 512 bytes; so ST_BLKSIZE code below, in preparation
367 for some cleanup in this area, later. */
369 /* Get or fake the disk device blocksize. Usually defined by sys/param.h
372 #if !defined(DEV_BSIZE) && defined(BSIZE)
373 # define DEV_BSIZE BSIZE
375 #if !defined(DEV_BSIZE) && defined(BBSIZE) /* SGI */
376 # define DEV_BSIZE BBSIZE
379 # define DEV_BSIZE 4096
382 /* Extract or fake data from a `struct stat'. ST_BLKSIZE gives the
383 optimal I/O blocksize for the file, in bytes. Some systems, like
384 Sequents, return st_blksize of 0 on pipes. */
387 # define ST_BLKSIZE(Statbuf) DEV_BSIZE
389 # define ST_BLKSIZE(Statbuf) \
390 ((Statbuf).st_blksize > 0 ? (Statbuf).st_blksize : DEV_BSIZE)
393 /* Extract or fake data from a `struct stat'. ST_NBLOCKS gives the
394 number of ST_NBLOCKSIZE-byte blocks in the file (including indirect blocks).
395 HP-UX counts st_blocks in 1024-byte units,
396 this loses when mixing HP-UX and BSD filesystems with NFS. AIX PS/2
397 counts st_blocks in 4K units. */
400 # if defined(_POSIX_SOURCE) || !defined(BSIZE)
401 # define ST_NBLOCKS(Statbuf) ((Statbuf).st_size / ST_NBLOCKSIZE + ((Statbuf).st_size % ST_NBLOCKSIZE != 0))
404 # define ST_NBLOCKS(Statbuf) (st_blocks ((Statbuf).st_size))
407 # define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks)
408 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
409 # define ST_NBLOCKSIZE 1024
411 # if defined(_AIX) && defined(_I386)
412 # define ST_NBLOCKSIZE (4 * 1024)
417 #ifndef ST_NBLOCKSIZE
418 #define ST_NBLOCKSIZE 512
421 /* This is a real challenge to properly get MTIO* symbols :-(. ISC uses
422 <sys/gentape.h>. SCO and BSDi uses <sys/tape.h>; BSDi also requires
423 <sys/tprintf.h> and <sys/device.h> for defining tp_dev and tpr_t. It
424 seems that the rest use <sys/mtio.h>, which itself requires other files,
425 depending on systems. Pyramid defines _IOW in <sgtty.h>, for example. */
427 #if HAVE_SYS_GENTAPE_H
428 # include <sys/gentape.h>
431 # if HAVE_SYS_DEVICE_H
432 # include <sys/device.h>
435 # include <sys/buf.h>
437 # if HAVE_SYS_TPRINTF_H
438 # include <sys/tprintf.h>
440 # include <sys/tape.h>
443 # include <sys/ioctl.h>
447 # if HAVE_SYS_IO_TRIOCTL_H
448 # include <sys/io/trioctl.h>
450 # include <sys/mtio.h>
455 /* Declare standard functions. */
466 # include <stdbool.h>
468 typedef enum {false = 0, true = 1} bool;
473 #ifndef _POSIX_VERSION
483 # define DMALLOC_FUNC_CHECK
484 # include <dmalloc.h>
496 # define CHAR_MAX TYPE_MAXIMUM (char)
500 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
504 # define LONG_MAX TYPE_MAXIMUM (long)
508 # define MB_LEN_MAX 1
512 # include <inttypes.h>
515 /* These macros work even on ones'-complement hosts (!).
516 The extra casts work around common compiler bugs. */
517 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
518 #define TYPE_MINIMUM(t) (TYPE_SIGNED (t) \
519 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
521 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
523 /* Bound on length of the string representing an integer value of type t.
524 Subtract one for the sign bit if t is signed;
525 302 / 1000 is log10 (2) rounded up;
526 add one for integer division truncation;
527 add one more for a minus sign if t is signed. */
528 #define INT_STRLEN_BOUND(t) \
529 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
530 + 1 + TYPE_SIGNED (t))
532 #define UINTMAX_STRSIZE_BOUND (INT_STRLEN_BOUND (uintmax_t) + 1)
534 /* Prototypes for external functions. */
538 # define PARAMS(Args) Args
540 # define PARAMS(Args) ()
548 # define setlocale(Category, Locale) /* empty */
552 # include <libintl.h>
553 # define _(Text) gettext (Text)
555 # undef bindtextdomain
556 # define bindtextdomain(Domain, Directory) /* empty */
558 # define textdomain(Domain) /* empty */
559 # define _(Text) Text
561 #define N_(Text) Text
568 /* Library modules. */
576 char *strstr
PARAMS ((const char *, const char *));
584 # define valloc(Size) malloc (Size)
587 char *xstrdup
PARAMS ((char const *));