]>
Dogcows Code - chaz/tar/blob - src/system.h
1 /* System dependent definitions for GNU tar.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
4 2004 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 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.
28 /* This feature is available in gcc versions 2.5 and later. */
29 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
30 # define __attribute__(spec) /* empty */
34 #include <sys/types.h>
37 /* IN_CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
38 as an argument to <ctype.h> macros like `isspace'. */
40 # define IN_CTYPE_DOMAIN(c) 1
42 # define IN_CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
45 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
46 #define ISODIGIT(c) ((unsigned) (c) - '0' <= 7)
47 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
48 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
50 /* Declare string and memory handling routines. Take care that an ANSI
51 string.h and pre-ANSI memory.h might conflict, and that memory.h and
52 strings.h conflict on some systems. */
54 #if STDC_HEADERS || HAVE_STRING_H
56 # if !STDC_HEADERS && HAVE_MEMORY_H
65 # define strrchr rindex
68 # define memcpy(d, s, n) bcopy ((char const *) (s), (char *) (d), n)
71 # define memcmp(a, b, n) bcmp ((char const *) (a), (char const *) (b), n)
82 /* Declare open parameters. */
87 # include <sys/file.h>
89 /* Pick only one of the next three: */
91 # define O_RDONLY 0 /* only allow read */
94 # define O_WRONLY 1 /* only allow write */
97 # define O_RDWR 2 /* both are allowed */
100 # define O_ACCMODE (O_RDONLY | O_RDWR | O_WRONLY)
102 /* The rest can be OR-ed in to the above: */
104 # define O_CREAT 8 /* create file if needed */
107 # define O_EXCL 16 /* file cannot already exist */
110 # define O_TRUNC 32 /* truncate file on open */
112 /* MS-DOG forever, with my love! */
117 /* Declare file status routines and bits. */
119 #include <sys/stat.h>
121 #if !HAVE_LSTAT && !defined lstat
125 #if STX_HIDDEN && !_LARGE_FILES /* AIX */
129 # define stat(file_name, buf) statx (file_name, buf, STATSIZE, STX_HIDDEN)
133 # define lstat(file_name, buf) statx (file_name, buf, STATSIZE, STX_HIDDEN | STX_LINK)
136 #if STAT_MACROS_BROKEN
147 /* On MSDOS, there are missing things from <sys/stat.h>. */
155 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
158 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
163 # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
165 # define S_ISBLK(mode) 0
170 # define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
172 # define S_ISCHR(mode) 0
177 # define S_ISCTG(mode) (((mode) & S_IFMT) == S_IFCTG)
179 # define S_ISCTG(mode) 0
183 # define S_ISDOOR(mode) 0
187 # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
189 # define S_ISFIFO(mode) 0
194 # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
196 # define S_ISLNK(mode) 0
201 # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
203 # define S_ISSOCK(mode) 0
207 #if !HAVE_MKFIFO && !defined mkfifo && defined S_IFIFO
208 # define mkfifo(file_name, mode) (mknod (file_name, (mode) | S_IFIFO, 0))
212 # define S_ISUID 0004000
215 # define S_ISGID 0002000
218 # define S_ISVTX 0001000
221 # define S_IRUSR 0000400
224 # define S_IWUSR 0000200
227 # define S_IXUSR 0000100
230 # define S_IRGRP 0000040
233 # define S_IWGRP 0000020
236 # define S_IXGRP 0000010
239 # define S_IROTH 0000004
242 # define S_IWOTH 0000002
245 # define S_IXOTH 0000001
248 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
249 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
250 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
251 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
252 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
254 /* Include <unistd.h> before any preprocessor test of _POSIX_VERSION. */
270 # define STDIN_FILENO 0
272 #ifndef STDOUT_FILENO
273 # define STDOUT_FILENO 1
275 #ifndef STDERR_FILENO
276 # define STDERR_FILENO 2
279 /* Declare make device, major and minor. Since major is a function on
280 SVR4, we have to resort to GOT_MAJOR instead of just testing if
281 major is #define'd. */
284 # include <sys/mkdev.h>
288 #if MAJOR_IN_SYSMACROS
289 # include <sys/sysmacros.h>
293 /* Some <sys/types.h> defines the macros. */
300 # define major(device) (device)
301 # define minor(device) (device)
302 # define makedev(major, minor) (((major) << 8) | (minor))
307 /* For HP-UX before HP-UX 8, major/minor are not in <sys/sysmacros.h>. */
309 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
310 # include <sys/mknod.h>
316 # define major(device) (((device) >> 8) & 0xff)
317 # define minor(device) ((device) & 0xff)
318 # define makedev(major, minor) (((major) << 8) | (minor))
323 /* Declare wait status. */
326 # include <sys/wait.h>
329 # define WEXITSTATUS(s) (((s) >> 8) & 0xff)
332 # define WIFSIGNALED(s) (((s) & 0xffff) - 1 < (unsigned) 0xff)
335 # define WTERMSIG(s) ((s) & 0x7f)
338 /* FIXME: It is wrong to use BLOCKSIZE for buffers when the logical block
339 size is greater than 512 bytes; so ST_BLKSIZE code below, in preparation
340 for some cleanup in this area, later. */
342 /* Extract or fake data from a `struct stat'. ST_BLKSIZE gives the
343 optimal I/O blocksize for the file, in bytes. Some systems, like
344 Sequents, return st_blksize of 0 on pipes. */
346 #define DEFAULT_ST_BLKSIZE 512
349 # define ST_BLKSIZE(statbuf) DEFAULT_ST_BLKSIZE
351 # define ST_BLKSIZE(statbuf) \
352 ((statbuf).st_blksize > 0 ? (statbuf).st_blksize : DEFAULT_ST_BLKSIZE)
355 /* Extract or fake data from a `struct stat'. ST_NBLOCKS gives the
356 number of ST_NBLOCKSIZE-byte blocks in the file (including indirect blocks).
357 HP-UX counts st_blocks in 1024-byte units,
358 this loses when mixing HP-UX and BSD filesystems with NFS. AIX PS/2
359 counts st_blocks in 4K units. */
362 # if defined(_POSIX_SOURCE) || !defined(BSIZE)
363 # define ST_NBLOCKS(statbuf) ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
366 # define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
369 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
370 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
371 # define ST_NBLOCKSIZE 1024
373 # if defined(_AIX) && defined(_I386)
374 # define ST_NBLOCKSIZE (4 * 1024)
379 #ifndef ST_NBLOCKSIZE
380 #define ST_NBLOCKSIZE 512
383 /* This is a real challenge to properly get MTIO* symbols :-(. ISC uses
384 <sys/gentape.h>. SCO and BSDi uses <sys/tape.h>; BSDi also requires
385 <sys/tprintf.h> and <sys/device.h> for defining tp_dev and tpr_t. It
386 seems that the rest use <sys/mtio.h>, which itself requires other files,
387 depending on systems. Pyramid defines _IOW in <sgtty.h>, for example. */
389 #if HAVE_SYS_GENTAPE_H
390 # include <sys/gentape.h>
393 # if HAVE_SYS_DEVICE_H
394 # include <sys/device.h>
396 # if HAVE_SYS_PARAM_H
397 # include <sys/param.h>
400 # include <sys/buf.h>
402 # if HAVE_SYS_TPRINTF_H
403 # include <sys/tprintf.h>
405 # include <sys/tape.h>
408 # include <sys/ioctl.h>
412 # if HAVE_SYS_IO_TRIOCTL_H
413 # include <sys/io/trioctl.h>
415 # include <sys/mtio.h>
420 /* Declare standard functions. */
433 #if !defined _POSIX_VERSION && MSDOS
438 # undef HAVE_DECL_VALLOC
439 # define DMALLOC_FUNC_CHECK
440 # include <dmalloc.h>
446 # define MB_LEN_MAX 1
450 # include <inttypes.h>
453 /* These macros work even on ones'-complement hosts (!).
454 The extra casts work around common compiler bugs. */
455 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
456 #define TYPE_MINIMUM(t) (TYPE_SIGNED (t) \
457 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
459 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
461 /* Bound on length of the string representing an integer value of type t.
462 Subtract one for the sign bit if t is signed;
463 302 / 1000 is log10 (2) rounded up;
464 add one for integer division truncation;
465 add one more for a minus sign if t is signed. */
466 #define INT_STRLEN_BOUND(t) \
467 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
468 + 1 + TYPE_SIGNED (t))
470 #define UINTMAX_STRSIZE_BOUND (INT_STRLEN_BOUND (uintmax_t) + 1)
472 /* Prototypes for external functions. */
478 # define setlocale(category, locale) /* empty */
482 #if defined(HAVE_SYS_TIME_H) && defined(TIME_WITH_SYS_TIME)
483 # include <sys/time.h>
493 /* Library modules. */
498 #include <unlocked-io.h>
502 #define _(msgid) gettext (msgid)
503 #define N_(msgid) msgid
506 # include <process.h>
507 # define SET_BINARY_MODE(arc) setmode(arc, O_BINARY)
508 # define ERRNO_IS_EACCES errno == EACCES
509 # define mkdir(file, mode) (mkdir) (file)
513 # define SET_BINARY_MODE(arc)
514 # define ERRNO_IS_EACCES 0
518 # include <sys/inode.h>
This page took 0.056974 seconds and 4 git commands to generate.