home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / tar-1.11.8-src.tgz / tar.out / fsf / tar / src / system.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  10KB  |  455 lines

  1. /* System dependent definitions for GNU tar.
  2.    Copyright (C) 1994 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
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. #ifdef 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. #ifdef __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. #ifdef HAVE_FCNTL_H
  103. # include <fcntl.h>
  104. #else
  105. # include <sys/file.h>
  106. #endif
  107.  
  108. #ifndef    O_BINARY
  109. # define O_BINARY 0
  110. #endif
  111. #ifndef O_CREAT
  112. # define O_CREAT 0
  113. #endif
  114. #ifndef    O_NDELAY
  115. # define O_NDELAY 0
  116. #endif
  117. #ifndef    O_RDONLY
  118. # define O_RDONLY 0
  119. #endif
  120. #ifndef O_RDWR
  121. # define O_RDWR 2
  122. #endif
  123.  
  124. /* Declare file status routines and bits.  */
  125.  
  126. #include <sys/stat.h>
  127.  
  128. #ifdef STAT_MACROS_BROKEN
  129. # undef S_ISBLK
  130. # undef S_ISCHR
  131. # undef S_ISDIR
  132. # undef S_ISFIFO
  133. # undef S_ISLNK
  134. # undef S_ISMPB
  135. # undef S_ISMPC
  136. # undef S_ISNWK
  137. # undef S_ISREG
  138. # undef S_ISSOCK
  139. #endif
  140.  
  141. /* On MSDOS, there are missing things from <sys/stat.h>.  */
  142. #ifdef __MSDOS__
  143. # define S_ISUID 0
  144. # define S_ISGID 0
  145. # define S_ISVTX 0
  146. #endif
  147.  
  148. #ifndef S_ISREG            /* POSIX.1 stat stuff missing */
  149. # define mode_t unsigned short
  150. #endif
  151. #if !defined(S_ISBLK) && defined(S_IFBLK)
  152. # define S_ISBLK(Mode) (((Mode) & S_IFMT) == S_IFBLK)
  153. #endif
  154. #if !defined(S_ISCHR) && defined(S_IFCHR)
  155. # define S_ISCHR(Mode) (((Mode) & S_IFMT) == S_IFCHR)
  156. #endif
  157. #if !defined(S_ISDIR) && defined(S_IFDIR)
  158. # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
  159. #endif
  160. #if !defined(S_ISREG) && defined(S_IFREG)
  161. # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
  162. #endif
  163. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  164. # define S_ISFIFO(Mode) (((Mode) & S_IFMT) == S_IFIFO)
  165. #endif
  166. #if !defined(S_ISLNK) && defined(S_IFLNK)
  167. # define S_ISLNK(Mode) (((Mode) & S_IFMT) == S_IFLNK)
  168. #endif
  169. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  170. # define S_ISSOCK(Mode) (((Mode) & S_IFMT) == S_IFSOCK)
  171. #endif
  172. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  173. # define S_ISMPB(Mode) (((Mode) & S_IFMT) == S_IFMPB)
  174. # define S_ISMPC(Mode) (((Mode) & S_IFMT) == S_IFMPC)
  175. #endif
  176. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  177. # define S_ISNWK(Mode) (((Mode) & S_IFMT) == S_IFNWK)
  178. #endif
  179.  
  180. #ifndef HAVE_MKFIFO
  181. # define mkfifo(Path, Mode) (mknod (Path, (Mode) | S_IFIFO, 0))
  182. #endif
  183.  
  184. #if !defined(S_ISCTG) && defined(S_IFCTG) /* contiguous file */
  185. # define S_ISCTG(Mode) (((Mode) & S_IFMT) == S_IFCTG)
  186. #endif
  187. #if !defined(S_ISVTX)
  188. # define S_ISVTX 0001000
  189. #endif
  190.  
  191. #ifndef _POSIX_SOURCE
  192. # include <sys/param.h>
  193. #endif
  194.  
  195. /* Include <unistd.h> before any preprocessor test of _POSIX_VERSION.  */
  196. #ifdef HAVE_UNISTD_H
  197. # include <unistd.h>
  198. #endif
  199.  
  200. /* Declare make device, major and minor.  Since major is a function on
  201.    SVR4, we have to resort to GOT_MAJOR instead of just testing if
  202.    major is #define'd.  */
  203.  
  204. #ifdef MAJOR_IN_MKDEV
  205. # include <sys/mkdev.h>
  206. # define GOT_MAJOR
  207. #endif
  208.  
  209. #ifdef MAJOR_IN_SYSMACROS
  210. # include <sys/sysmacros.h>
  211. # define GOT_MAJOR
  212. #endif
  213.  
  214. /* Some <sys/types.h> defines the macros. */
  215. #ifdef major
  216. # define GOT_MAJOR
  217. #endif
  218.  
  219. #ifndef GOT_MAJOR
  220. # ifdef __MSDOS__
  221. #  define major(Device)        (Device)
  222. #  define minor(Device)        (Device)
  223. #  define makedev(Major, Minor)    (((Major) << 8) | (Minor))
  224. #  define GOT_MAJOR
  225. # endif
  226. #endif
  227.  
  228. /* For HP-UX before HP-UX 8, major/minor are not in <sys/sysmacros.h>.  */
  229. #ifndef GOT_MAJOR
  230. # if defined(hpux) || defined(__hpux__) || defined(__hpux)
  231. #  include <sys/mknod.h>
  232. #  define GOT_MAJOR
  233. # endif
  234. #endif
  235.  
  236. #ifndef GOT_MAJOR
  237. # define major(Device)        (((Device) >> 8) & 0xff)
  238. # define minor(Device)        ((Device) & 0xff)
  239. # define makedev(Major, Minor)    (((Major) << 8) | (Minor))
  240. #endif
  241.  
  242. #undef GOT_MAJOR
  243.  
  244. /* Declare directory reading routines and structures.  */
  245.  
  246. #ifdef __MSDOS__
  247. # include "msd_dir.h"
  248. # define NAMLEN(dirent) ((dirent)->d_namlen)
  249. #else
  250. # ifdef HAVE_DIRENT_H
  251. #  include <dirent.h>
  252. #  define NAMLEN(dirent) (strlen((dirent)->d_name))
  253. # else
  254. #  define dirent direct
  255. #  define NAMLEN(dirent) ((dirent)->d_namlen)
  256. #  ifdef HAVE_SYS_NDIR_H
  257. #   include <sys/ndir.h>
  258. #  endif
  259. #  ifdef HAVE_SYS_DIR_H
  260. #   include <sys/dir.h>
  261. #  endif
  262. #  ifdef HAVE_NDIR_H
  263. #   include <ndir.h>
  264. #  endif
  265. # endif
  266. #endif
  267.  
  268. /* Declare wait status.  */
  269.  
  270. #ifdef HAVE_SYS_WAIT_H
  271. # include <sys/wait.h>
  272. #endif
  273.  
  274. #ifdef HAVE_UNION_WAIT
  275. # define WAIT_T union wait
  276. # ifndef WTERMSIG
  277. #  define WTERMSIG(Status)     ((Status).w_termsig)
  278. # endif
  279. # ifndef WCOREDUMP
  280. #  define WCOREDUMP(Status)    ((Status).w_coredump)
  281. # endif
  282. # ifndef WEXITSTATUS
  283. #  define WEXITSTATUS(Status)  ((Status).w_retcode)
  284. # endif
  285. #else
  286. # define WAIT_T int
  287. # ifndef WTERMSIG
  288. #  define WTERMSIG(Status)     ((Status) & 0x7f)
  289. # endif
  290. # ifndef WCOREDUMP
  291. #  define WCOREDUMP(Status)    ((Status) & 0x80)
  292. # endif
  293. # ifndef WEXITSTATUS
  294. #  define WEXITSTATUS(Status)  (((Status) >> 8) & 0xff)
  295. # endif
  296. #endif
  297.  
  298. #ifndef WIFSTOPPED
  299. # define WIFSTOPPED(Status)    (WTERMSIG(Status) == 0x7f)
  300. #endif
  301. #ifndef WIFSIGNALED
  302. # define WIFSIGNALED(Status)   (WTERMSIG(Status) != 0)
  303. #endif
  304. #ifndef WIFEXITED
  305. # define WIFEXITED(Status)     (WTERMSIG(Status) == 0)
  306. #endif
  307.      
  308. /* It is wrong to use RECORDSIZE for buffers when the logical block size
  309.    is greater than 512 bytes; so ST_BLKSIZE code below, in preparation
  310.    for some cleanup in this area, later.  FIXME.  */
  311.  
  312. /* Get or fake the disk device blocksize.  Usually defined by sys/param.h
  313.    (if at all).  */
  314.  
  315. #if !defined(DEV_BSIZE) && defined(BSIZE)
  316. # define DEV_BSIZE BSIZE
  317. #endif
  318. #if !defined(DEV_BSIZE) && defined(BBSIZE) /* SGI */
  319. # define DEV_BSIZE BBSIZE
  320. #endif
  321. #ifndef DEV_BSIZE
  322. # define DEV_BSIZE 4096
  323. #endif
  324.  
  325. /* Extract or fake data from a `struct stat'.  ST_BLKSIZE gives the
  326.    optimal I/O blocksize for the file, in bytes.  Some systems, like
  327.    Sequents, return st_blksize of 0 on pipes.  */
  328.  
  329. #ifndef HAVE_ST_BLKSIZE
  330. # define ST_BLKSIZE(Statbuf) DEV_BSIZE
  331. #else
  332. # define ST_BLKSIZE(Statbuf) \
  333.     ((Statbuf).st_blksize > 0 ? (Statbuf).st_blksize : DEV_BSIZE)
  334. #endif
  335.  
  336. /* Extract or fake data from a `struct stat'.  ST_NBLOCKS gives the
  337.    number of 512-byte blocks in the file (including indirect blocks).
  338.    fileblocks.c uses BSIZE.  HP-UX counts st_blocks in 1024-byte units,
  339.    this loses when mixing HP-UX and BSD filesystems with NFS.  AIX PS/2
  340.    counts st_blocks in 4K units.  */
  341.  
  342. #ifndef HAVE_ST_BLOCKS
  343. # if defined(_POSIX_SOURCE) || !defined(BSIZE)
  344. #  define ST_NBLOCKS(Statbuf) (((Statbuf).st_size + 512 - 1) / 512)
  345. # else
  346. #  define ST_NBLOCKS(Statbuf) (st_blocks ((Statbuf).st_size))
  347. # endif
  348. #else
  349. # if defined(hpux) || defined(__hpux__) || defined(__hpux)
  350. #  define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks * 2)
  351. # else
  352. #  if defined(_AIX) && defined(_I386)
  353. #   define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks * 8)
  354. #  else
  355. #   define ST_NBLOCKS(Statbuf) ((Statbuf).st_blocks)
  356. #  endif
  357. # endif
  358. #endif
  359.  
  360. #if HAVE_SYS_GENTAPE_H        /* e.g., for ISC */
  361. # include <sys/gentape.h>
  362. #else
  363. # if HAVE_SYS_TAPE_H        /* e.g., for SCO */
  364. #  include <sys/tape.h>
  365. # else
  366. #  if HAVE_SYS_MTIO_H
  367. #   include <sys/ioctl.h>
  368. #   if HAVE_SYS_IO_TRIOCTL_H
  369. #    include <sys/io/trioctl.h>
  370. #   endif
  371. #   include <sys/mtio.h>
  372. #  endif
  373. # endif
  374. #endif
  375.  
  376. /* Declare standard functions.  */
  377.  
  378. #ifdef STDC_HEADERS
  379. # include <stdlib.h>
  380. #else
  381. voidstar malloc ();
  382. voidstar realloc ();
  383. # ifdef HAVE_GETCWD
  384. char *getcwd ();
  385. # endif
  386. char *getenv ();
  387. #endif
  388.  
  389. #include <stdio.h>
  390.  
  391. #ifndef _POSIX_VERSION
  392. # ifdef __MSDOS__
  393. #  include <io.h>
  394. # else
  395. off_t lseek ();
  396. # endif
  397. #endif
  398.  
  399. #include <pathmax.h>
  400.  
  401. /* Until getoptold function is declared in getopt.h, we need this here for
  402.    struct option.  */
  403. #include <getopt.h>
  404.  
  405. #ifdef WITH_DMALLOC
  406. # undef HAVE_VALLOC
  407. # define DMALLOC_FUNC_CHECK
  408. # include <dmalloc.h>
  409. #endif
  410.  
  411. /* Prototypes for external functions.  */
  412.  
  413. #ifndef __P
  414. # if PROTOTYPES
  415. #  define __P(Args) Args
  416. # else
  417. #  define __P(Args) ()
  418. # endif
  419. #endif
  420.  
  421. #if HAVE_LOCALE_H
  422. # include <locale.h>
  423. #endif
  424. #if !HAVE_SETLOCALE
  425. # define setlocale(Category, Locale)
  426. #endif
  427.  
  428. #if ENABLE_NLS
  429. # include <libintl.h>
  430. # define _(Text) gettext (Text)
  431. #else
  432. # define textdomain(Domain)
  433. # define _(Text) Text
  434. #endif
  435.  
  436. /* Library modules.  */
  437.  
  438. #ifdef HAVE_VPRINTF
  439. void error __P ((int, int, const char *, ...));
  440. #else
  441. void error ();
  442. #endif
  443.  
  444. #ifndef HAVE_STRSTR
  445. char *strstr __P ((const char *, const char *));
  446. #endif
  447.  
  448. #ifndef HAVE_VALLOC
  449. # define valloc(Size) malloc (Size)
  450. #endif
  451.  
  452. voidstar xmalloc __P ((size_t));
  453. voidstar xrealloc __P ((voidstar, size_t));
  454. char *xstrdup __P ((const char *));
  455.