]>
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 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(path, buf) statx (path, buf, STATSIZE, STX_HIDDEN)
133 # define lstat(path, buf) statx (path, 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(Path, Mode) (mknod (Path, (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>
397 # include <sys/buf.h>
399 # if HAVE_SYS_TPRINTF_H
400 # include <sys/tprintf.h>
402 # include <sys/tape.h>
405 # include <sys/ioctl.h>
409 # if HAVE_SYS_IO_TRIOCTL_H
410 # include <sys/io/trioctl.h>
412 # include <sys/mtio.h>
417 /* Declare standard functions. */
430 #if !defined _POSIX_VERSION && MSDOS
435 # undef HAVE_DECL_VALLOC
436 # define DMALLOC_FUNC_CHECK
437 # include <dmalloc.h>
443 # define MB_LEN_MAX 1
447 # include <inttypes.h>
450 /* These macros work even on ones'-complement hosts (!).
451 The extra casts work around common compiler bugs. */
452 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
453 #define TYPE_MINIMUM(t) (TYPE_SIGNED (t) \
454 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
456 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
458 /* Bound on length of the string representing an integer value of type t.
459 Subtract one for the sign bit if t is signed;
460 302 / 1000 is log10 (2) rounded up;
461 add one for integer division truncation;
462 add one more for a minus sign if t is signed. */
463 #define INT_STRLEN_BOUND(t) \
464 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
465 + 1 + TYPE_SIGNED (t))
467 #define UINTMAX_STRSIZE_BOUND (INT_STRLEN_BOUND (uintmax_t) + 1)
469 /* Prototypes for external functions. */
475 # define setlocale(Category, Locale) /* empty */
483 /* Library modules. */
488 #include <unlocked-io.h>
492 #define _(msgid) gettext (msgid)
493 #define N_(msgid) msgid
495 #if ! defined valloc && ! HAVE_DECL_VALLOC
496 # define valloc(Size) malloc (Size)
500 # include <process.h>
501 # define SET_BINARY_MODE(arc) setmode(arc, O_BINARY)
502 # define ERRNO_IS_EACCES errno == EACCES
503 # define mkdir(file, mode) (mkdir) (file)
507 # define SET_BINARY_MODE(arc)
508 # define ERRNO_IS_EACCES 0
512 # include <sys/inode.h>
This page took 0.052818 seconds and 4 git commands to generate.