1 /* System dependent definitions for GNU tar.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
4 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
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 3, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
27 /* This feature is available in gcc versions 2.5 and later. */
28 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
29 # define __attribute__(spec) /* empty */
33 #include <sys/types.h>
36 /* IN_CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
37 as an argument to <ctype.h> macros like `isspace'. */
39 # define IN_CTYPE_DOMAIN(c) 1
41 # define IN_CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
44 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
45 #define ISODIGIT(c) ((unsigned) (c) - '0' <= 7)
46 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
47 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
49 /* Declare string and memory handling routines. Take care that an ANSI
50 string.h and pre-ANSI memory.h might conflict, and that memory.h and
51 strings.h conflict on some systems. */
53 #if STDC_HEADERS || HAVE_STRING_H
55 # if !STDC_HEADERS && HAVE_MEMORY_H
64 # define strrchr rindex
67 # define memcpy(d, s, n) bcopy ((char const *) (s), (char *) (d), n)
70 # define memcmp(a, b, n) bcmp ((char const *) (a), (char const *) (b), n)
81 /* Declare open parameters. */
86 # include <sys/file.h>
88 /* Pick only one of the next three: */
90 # define O_RDONLY 0 /* only allow read */
93 # define O_WRONLY 1 /* only allow write */
96 # define O_RDWR 2 /* both are allowed */
99 # define O_ACCMODE (O_RDONLY | O_RDWR | O_WRONLY)
101 /* The rest can be OR-ed in to the above: */
103 # define O_CREAT 8 /* create file if needed */
106 # define O_EXCL 16 /* file cannot already exist */
109 # define O_TRUNC 32 /* truncate file on open */
116 # define O_DIRECTORY 0
122 # define O_NONBLOCK 0
125 /* Declare file status routines and bits. */
127 #include <sys/stat.h>
129 #if !HAVE_LSTAT && !defined lstat
133 #if STX_HIDDEN && !_LARGE_FILES /* AIX */
137 # define stat(file_name, buf) statx (file_name, buf, STATSIZE, STX_HIDDEN)
141 # define lstat(file_name, buf) statx (file_name, buf, STATSIZE, STX_HIDDEN | STX_LINK)
144 #if STAT_MACROS_BROKEN
155 /* On MSDOS, there are missing things from <sys/stat.h>. */
163 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
166 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
171 # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
173 # define S_ISBLK(mode) 0
178 # define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
180 # define S_ISCHR(mode) 0
185 # define S_ISCTG(mode) (((mode) & S_IFMT) == S_IFCTG)
187 # define S_ISCTG(mode) 0
191 # define S_ISDOOR(mode) 0
195 # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
197 # define S_ISFIFO(mode) 0
202 # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
204 # define S_ISLNK(mode) 0
209 # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
211 # define S_ISSOCK(mode) 0
215 #if !HAVE_MKFIFO && !defined mkfifo && defined S_IFIFO
216 # define mkfifo(file_name, mode) (mknod (file_name, (mode) | S_IFIFO, 0))
220 # define S_ISUID 0004000
223 # define S_ISGID 0002000
226 # define S_ISVTX 0001000
229 # define S_IRUSR 0000400
232 # define S_IWUSR 0000200
235 # define S_IXUSR 0000100
238 # define S_IRGRP 0000040
241 # define S_IWGRP 0000020
244 # define S_IXGRP 0000010
247 # define S_IROTH 0000004
250 # define S_IWOTH 0000002
253 # define S_IXOTH 0000001
256 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
257 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
258 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
259 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
260 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
262 /* Include <unistd.h> before any preprocessor test of _POSIX_VERSION. */
276 # define STDIN_FILENO 0
278 #ifndef STDOUT_FILENO
279 # define STDOUT_FILENO 1
281 #ifndef STDERR_FILENO
282 # define STDERR_FILENO 2
285 /* Declare make device, major and minor. Since major is a function on
286 SVR4, we have to resort to GOT_MAJOR instead of just testing if
287 major is #define'd. */
290 # include <sys/mkdev.h>
291 # if !defined(makedev) && defined(mkdev)
292 # define makedev(a,b) mkdev((a),(b))
297 #if MAJOR_IN_SYSMACROS
298 # include <sys/sysmacros.h>
302 /* Some <sys/types.h> defines the macros. */
309 # define major(device) (device)
310 # define minor(device) (device)
311 # define makedev(major, minor) (((major) << 8) | (minor))
316 /* For HP-UX before HP-UX 8, major/minor are not in <sys/sysmacros.h>. */
318 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
319 # include <sys/mknod.h>
325 # define major(device) (((device) >> 8) & 0xff)
326 # define minor(device) ((device) & 0xff)
327 # define makedev(major, minor) (((major) << 8) | (minor))
332 /* Declare wait status. */
335 # include <sys/wait.h>
338 # define WEXITSTATUS(s) (((s) >> 8) & 0xff)
341 # define WIFSIGNALED(s) (((s) & 0xffff) - 1 < (unsigned) 0xff)
344 # define WTERMSIG(s) ((s) & 0x7f)
347 /* FIXME: It is wrong to use BLOCKSIZE for buffers when the logical block
348 size is greater than 512 bytes; so ST_BLKSIZE code below, in preparation
349 for some cleanup in this area, later. */
351 /* Extract or fake data from a `struct stat'. ST_BLKSIZE gives the
352 optimal I/O blocksize for the file, in bytes. Some systems, like
353 Sequents, return st_blksize of 0 on pipes. */
355 #define DEFAULT_ST_BLKSIZE 512
358 # define ST_BLKSIZE(statbuf) DEFAULT_ST_BLKSIZE
360 # define ST_BLKSIZE(statbuf) \
361 ((statbuf).st_blksize > 0 ? (statbuf).st_blksize : DEFAULT_ST_BLKSIZE)
364 /* Extract or fake data from a `struct stat'. ST_NBLOCKS gives the
365 number of ST_NBLOCKSIZE-byte blocks in the file (including indirect blocks).
366 HP-UX counts st_blocks in 1024-byte units,
367 this loses when mixing HP-UX and BSD filesystems with NFS. AIX PS/2
368 counts st_blocks in 4K units. */
371 # if defined(_POSIX_SOURCE) || !defined(BSIZE)
372 # define ST_NBLOCKS(statbuf) ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
375 # define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
378 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
379 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
380 # define ST_NBLOCKSIZE 1024
382 # if defined(_AIX) && defined(_I386)
383 # define ST_NBLOCKSIZE (4 * 1024)
388 #ifndef ST_NBLOCKSIZE
389 # define ST_NBLOCKSIZE 512
392 #define ST_IS_SPARSE(st) \
394 < ((st).st_size / ST_NBLOCKSIZE + ((st).st_size % ST_NBLOCKSIZE != 0)))
396 /* Declare standard functions. */
409 #if !defined _POSIX_VERSION && MSDOS
414 # define DMALLOC_FUNC_CHECK
415 # include <dmalloc.h>
421 # define MB_LEN_MAX 1
424 #include <inttypes.h>
426 #include <intprops.h>
428 #define UINTMAX_STRSIZE_BOUND INT_BUFSIZE_BOUND (uintmax_t)
430 /* Prototypes for external functions. */
436 # define setlocale(category, locale) /* empty */
440 #ifdef TIME_WITH_SYS_TIME
441 # include <sys/time.h>
444 /* Library modules. */
449 #include <unlocked-io.h>
453 #define _(msgid) gettext (msgid)
454 #define N_(msgid) msgid
464 # include <process.h>
465 # define SET_BINARY_MODE(arc) setmode(arc, O_BINARY)
466 # define ERRNO_IS_EACCES errno == EACCES
467 # define mkdir(file, mode) (mkdir) (file)
468 # define TTY_NAME "con"
469 # define sys_reset_uid_gid()
471 # define SET_BINARY_MODE(arc)
472 # define ERRNO_IS_EACCES 0
473 # define TTY_NAME "/dev/tty"
474 # define sys_reset_uid_gid() \
475 do { setuid (getuid ()); setgid (getgid ()); } while (0)
479 # include <sys/inode.h>