system.h 11 KB

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