]> Dogcows Code - chaz/tar/blob - src/system.h
(finish_header): Report block numbers with origin 0, not origin 1.
[chaz/tar] / src / system.h
1 /* System dependent definitions for GNU tar.
2 Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 /* Declare alloca. AIX requires this to be the first thing in the file. */
24
25 #if __GNUC__
26 # define alloca __builtin_alloca
27 #else
28 # if HAVE_ALLOCA_H
29 # include <alloca.h>
30 # else
31 # ifdef _AIX
32 #pragma alloca
33 # else
34 # ifndef alloca
35 char *alloca ();
36 # endif
37 # endif
38 # endif
39 #endif
40
41 #include <sys/types.h>
42
43 /* Declare a generic pointer type. */
44 #if __STDC__ || defined(__TURBOC__)
45 # define voidstar void *
46 #else
47 # define voidstar char *
48 #endif
49
50 /* Declare ISASCII. */
51
52 #include <ctype.h>
53
54 #if STDC_HEADERS
55 # define ISASCII(Char) 1
56 #else
57 # ifdef isascii
58 # define ISASCII(Char) isascii (Char)
59 # else
60 # if HAVE_ISASCII
61 # define ISASCII(Char) isascii (Char)
62 # else
63 # define ISASCII(Char) 1
64 # endif
65 # endif
66 #endif
67
68 /* Declare string and memory handling routines. Take care that an ANSI
69 string.h and pre-ANSI memory.h might conflict, and that memory.h and
70 strings.h conflict on some systems. */
71
72 #if STDC_HEADERS || HAVE_STRING_H
73 # include <string.h>
74 # if !STDC_HEADERS && HAVE_MEMORY_H
75 # include <memory.h>
76 # endif
77 #else
78 # include <strings.h>
79 # ifndef strchr
80 # define strchr index
81 # endif
82 # ifndef strrchr
83 # define strrchr rindex
84 # endif
85 # ifndef memcpy
86 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
87 # endif
88 # ifndef memcmp
89 # define memcmp(Src1, Src2, Num) bcmp (Src1, Src2, Num)
90 # endif
91 #endif
92
93 /* Declare errno. */
94
95 #include <errno.h>
96 #ifndef errno
97 extern int errno;
98 #endif
99
100 /* Declare open parameters. */
101
102 #if HAVE_FCNTL_H
103 # include <fcntl.h>
104 #else
105 # include <sys/file.h>
106 #endif
107 /* Pick only one of the next three: */
108 #ifndef O_RDONLY
109 # define O_RDONLY 0 /* only allow read */
110 #endif
111 #ifndef O_WRONLY
112 # define O_WRONLY 1 /* only allow write */
113 #endif
114 #ifndef O_RDWR
115 # define O_RDWR 2 /* both are allowed */
116 #endif
117 /* The rest can be OR-ed in to the above: */
118 #ifndef O_NDELAY
119 # define O_NDELAY 4 /* don't block on opening devices */
120 #endif
121 #ifndef O_CREAT
122 # define O_CREAT 8 /* create file if needed */
123 #endif
124 #ifndef O_EXCL
125 # define O_EXCL 16 /* file cannot already exist */
126 #endif
127 #ifndef O_TRUNC
128 # define O_TRUNC 32 /* truncate file on open */
129 #endif
130 #ifndef O_APPEND
131 # define O_APPEND 64 /* always write at end of file */
132 #endif
133 /* MS-DOG forever, with my love! */
134 #ifndef O_BINARY
135 # define O_BINARY 0
136 #endif
137 /* Emulate System V 3-argument open call */
138 #if EMUL_OPEN3
139 # define open open3
140 #endif
141
142 /* Declare file status routines and bits. */
143
144 #include <sys/stat.h>
145
146 #ifndef S_ISLNK
147 # define lstat stat
148 #endif
149
150 #if STAT_MACROS_BROKEN
151 # undef S_ISBLK
152 # undef S_ISCHR
153 # undef S_ISDIR
154 # undef S_ISFIFO
155 # undef S_ISLNK
156 # undef S_ISMPB
157 # undef S_ISMPC
158 # undef S_ISNWK
159 # undef S_ISREG
160 # undef S_ISSOCK
161 #endif
162
163 /* On MSDOS, there are missing things from <sys/stat.h>. */
164 #if MSDOS
165 # define S_ISUID 0
166 # define S_ISGID 0
167 # define S_ISVTX 0
168 #endif
169
170 #ifndef S_ISREG /* POSIX.1 stat stuff missing */
171 # define mode_t unsigned short
172 #endif
173 #if !defined(S_ISBLK) && defined(S_IFBLK)
174 # define S_ISBLK(Mode) (((Mode) & S_IFMT) == S_IFBLK)
175 #endif
176 #if !defined(S_ISCHR) && defined(S_IFCHR)
177 # define S_ISCHR(Mode) (((Mode) & S_IFMT) == S_IFCHR)
178 #endif
179 #if !defined(S_ISDIR) && defined(S_IFDIR)
180 # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
181 #endif
182 #if !defined(S_ISREG) && defined(S_IFREG)
183 # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
184 #endif
185 #if !defined(S_ISFIFO) && defined(S_IFIFO)
186 # define S_ISFIFO(Mode) (((Mode) & S_IFMT) == S_IFIFO)
187 #endif
188 #if !defined(S_ISLNK) && defined(S_IFLNK)
189 # define S_ISLNK(Mode) (((Mode) & S_IFMT) == S_IFLNK)
190 #endif
191 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
192 # define S_ISSOCK(Mode) (((Mode) & S_IFMT) == S_IFSOCK)
193 #endif
194 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
195 # define S_ISMPB(Mode) (((Mode) & S_IFMT) == S_IFMPB)
196 # define S_ISMPC(Mode) (((Mode) & S_IFMT) == S_IFMPC)
197 #endif
198 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
199 # define S_ISNWK(Mode) (((Mode) & S_IFMT) == S_IFNWK)
200 #endif
201
202 #if !HAVE_MKFIFO
203 # define mkfifo(Path, Mode) (mknod (Path, (Mode) | S_IFIFO, 0))
204 #endif
205
206 #if !defined(S_ISCTG) && defined(S_IFCTG) /* contiguous file */
207 # define S_ISCTG(Mode) (((Mode) & S_IFMT) == S_IFCTG)
208 #endif
209 #if !defined(S_ISVTX)
210 # define S_ISVTX 0001000
211 #endif
212
213 #ifndef _POSIX_SOURCE
214 # include <sys/param.h>
215 #endif
216
217 /* Include <unistd.h> before any preprocessor test of _POSIX_VERSION. */
218 #if HAVE_UNISTD_H
219 # include <unistd.h>
220 #endif
221
222 /* Declare make device, major and minor. Since major is a function on
223 SVR4, we have to resort to GOT_MAJOR instead of just testing if
224 major is #define'd. */
225
226 #if MAJOR_IN_MKDEV
227 # include <sys/mkdev.h>
228 # define GOT_MAJOR
229 #endif
230
231 #if MAJOR_IN_SYSMACROS
232 # include <sys/sysmacros.h>
233 # define GOT_MAJOR
234 #endif
235
236 /* Some <sys/types.h> defines the macros. */
237 #ifdef major
238 # define GOT_MAJOR
239 #endif
240
241 #ifndef GOT_MAJOR
242 # if MSDOS
243 # define major(Device) (Device)
244 # define minor(Device) (Device)
245 # define makedev(Major, Minor) (((Major) << 8) | (Minor))
246 # define GOT_MAJOR
247 # endif
248 #endif
249
250 /* For HP-UX before HP-UX 8, major/minor are not in <sys/sysmacros.h>. */
251 #ifndef GOT_MAJOR
252 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
253 # include <sys/mknod.h>
254 # define GOT_MAJOR
255 # endif
256 #endif
257
258 #ifndef GOT_MAJOR
259 # define major(Device) (((Device) >> 8) & 0xff)
260 # define minor(Device) ((Device) & 0xff)
261 # define makedev(Major, Minor) (((Major) << 8) | (Minor))
262 #endif
263
264 #undef GOT_MAJOR
265
266 /* Declare directory reading routines and structures. */
267
268 #if __TURBOC__
269 # include "msd_dir.h"
270 # define NAMLEN(dirent) ((dirent)->d_namlen)
271 #else
272 # if HAVE_DIRENT_H
273 # include <dirent.h>
274 # define NAMLEN(dirent) (strlen((dirent)->d_name))
275 # else
276 # define dirent direct
277 # define NAMLEN(dirent) ((dirent)->d_namlen)
278 # if HAVE_SYS_NDIR_H
279 # include <sys/ndir.h>
280 # endif
281 # if HAVE_SYS_DIR_H
282 # include <sys/dir.h>
283 # endif
284 # if HAVE_NDIR_H
285 # include <ndir.h>
286 # endif
287 # endif
288 #endif
289
290 /* Declare wait status. */
291
292 #if HAVE_SYS_WAIT_H
293 # include <sys/wait.h>
294 #endif
295
296 #if HAVE_UNION_WAIT
297 # define WAIT_T union wait
298 # ifndef WTERMSIG
299 # define WTERMSIG(Status) ((Status).w_termsig)
300 # endif
301 # ifndef WCOREDUMP
302 # define WCOREDUMP(Status) ((Status).w_coredump)
303 # endif
304 # ifndef WEXITSTATUS
305 # define WEXITSTATUS(Status) ((Status).w_retcode)
306 # endif
307 #else
308 # define WAIT_T int
309 # ifndef WTERMSIG
310 # define WTERMSIG(Status) ((Status) & 0x7f)
311 # endif
312 # ifndef WCOREDUMP
313 # define WCOREDUMP(Status) ((Status) & 0x80)
314 # endif
315 # ifndef WEXITSTATUS
316 # define WEXITSTATUS(Status) (((Status) >> 8) & 0xff)
317 # endif
318 #endif
319
320 #ifndef WIFSTOPPED
321 # define WIFSTOPPED(Status) (WTERMSIG(Status) == 0x7f)
322 #endif
323 #ifndef WIFSIGNALED
324 # define WIFSIGNALED(Status) (WTERMSIG(Status) != 0)
325 #endif
326 #ifndef WIFEXITED
327 # define WIFEXITED(Status) (WTERMSIG(Status) == 0)
328 #endif
329
330 /* FIXME: It is wrong to use BLOCKSIZE for buffers when the logical block
331 size is greater than 512 bytes; so ST_BLKSIZE code below, in preparation
332 for some cleanup in this area, later. */
333
334 /* Get or fake the disk device blocksize. Usually defined by sys/param.h
335 (if at all). */
336
337 #if !defined(DEV_BSIZE) && defined(BSIZE)
338 # define DEV_BSIZE BSIZE
339 #endif
340 #if !defined(DEV_BSIZE) && defined(BBSIZE) /* SGI */
341 # define DEV_BSIZE BBSIZE
342 #endif
343 #ifndef DEV_BSIZE
344 # define DEV_BSIZE 4096
345 #endif
346
347 /* Extract or fake data from a `struct stat'. ST_BLKSIZE gives the
348 optimal I/O blocksize for the file, in bytes. Some systems, like
349 Sequents, return st_blksize of 0 on pipes. */
350
351 #if !HAVE_ST_BLKSIZE
352 # define ST_BLKSIZE(Statbuf) DEV_BSIZE
353 #else
354 # define ST_BLKSIZE(Statbuf) \
355 ((Statbuf).st_blksize > 0 ? (Statbuf).st_blksize : DEV_BSIZE)
356 #endif
357
358 /* Extract or fake data from a `struct stat'. ST_NBLOCKS gives the
359 number of 512-byte blocks in the file (including indirect blocks).
360 fileblocks.c uses BSIZE. HP-UX counts st_blocks in 1024-byte units,
361 this loses when mixing HP-UX and BSD filesystems with NFS. AIX PS/2
362 counts st_blocks in 4K units. */
363
364 #if !HAVE_ST_BLOCKS
365 # if defined(_POSIX_SOURCE) || !defined(BSIZE)
366 # define ST_NBLOCKS(Statbuf) (((Statbuf).st_size + 512 - 1) / 512)
367 # else
368 # define ST_NBLOCKS(Statbuf) (st_blocks ((Statbuf).st_size))
369 # endif
370 #else
371 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
372 # define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks * 2)
373 # else
374 # if defined(_AIX) && defined(_I386)
375 # define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks * 8)
376 # else
377 # define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks)
378 # endif
379 # endif
380 #endif
381
382 /* This is a real challenge to properly get MTIO* symbols :-(. ISC uses
383 <sys/gentape.h>. SCO and BSDi uses <sys/tape.h>; BSDi also requires
384 <sys/tprintf.h> and <sys/device.h> for defining tp_dev and tpr_t. It
385 seems that the rest use <sys/mtio.h>, which itself requires other files,
386 depending on systems. Pyramid defines _IOW in <sgtty.h>, for example. */
387
388 #if HAVE_SYS_GENTAPE_H
389 # include <sys/gentape.h>
390 #else
391 # if HAVE_SYS_TAPE_H
392 # if HAVE_SYS_DEVICE_H
393 # include <sys/device.h>
394 # endif
395 # if HAVE_SYS_BUF_H
396 # include <sys/buf.h>
397 # endif
398 # if HAVE_SYS_TPRINTF_H
399 # include <sys/tprintf.h>
400 # endif
401 # include <sys/tape.h>
402 # else
403 # if HAVE_SYS_MTIO_H
404 # include <sys/ioctl.h>
405 # if HAVE_SGTTY_H
406 # include <sgtty.h>
407 # endif
408 # if HAVE_SYS_IO_TRIOCTL_H
409 # include <sys/io/trioctl.h>
410 # endif
411 # include <sys/mtio.h>
412 # endif
413 # endif
414 #endif
415
416 /* Declare standard functions. */
417
418 #if STDC_HEADERS
419 # include <stdlib.h>
420 #else
421 voidstar malloc ();
422 voidstar realloc ();
423 # if HAVE_GETCWD
424 char *getcwd ();
425 # endif
426 char *getenv ();
427 #endif
428
429 #include <stdio.h>
430
431 #ifndef _POSIX_VERSION
432 # if MSDOS
433 # include <io.h>
434 # else
435 off_t lseek ();
436 # endif
437 #endif
438
439 #include <pathmax.h>
440
441 #if WITH_DMALLOC
442 # undef HAVE_VALLOC
443 # define DMALLOC_FUNC_CHECK
444 # include <dmalloc.h>
445 #endif
446 \f
447 /* Prototypes for external functions. */
448
449 #ifndef PARAMS
450 # if PROTOTYPES
451 # define PARAMS(Args) Args
452 # else
453 # define PARAMS(Args) ()
454 # endif
455 #endif
456
457 #if HAVE_LOCALE_H
458 # include <locale.h>
459 #endif
460 #if !HAVE_SETLOCALE
461 # define setlocale(Category, Locale)
462 #endif
463
464 #if ENABLE_NLS
465 # include <libintl.h>
466 # define _(Text) gettext (Text)
467 #else
468 # define bindtextdomain(Domain, Directory)
469 # define textdomain(Domain)
470 # define _(Text) Text
471 #endif
472 #define N_(Text) Text
473
474 /* Library modules. */
475
476 #include "error.h"
477
478 #if !HAVE_STRSTR
479 char *strstr PARAMS ((const char *, const char *));
480 #endif
481
482 #if HAVE_VALLOC
483 # ifndef valloc
484 voidstar valloc PARAMS ((size_t));
485 # endif
486 #else
487 # define valloc(Size) malloc (Size)
488 #endif
489
490 voidstar xmalloc PARAMS ((size_t));
491 voidstar xrealloc PARAMS ((voidstar, size_t));
492 char *xstrdup PARAMS ((const char *));
This page took 0.059539 seconds and 4 git commands to generate.