port.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Portability declarations. Requires sys/types.h.
  2. Copyright (C) 1988, 1992 Free Software Foundation
  3. This file is part of GNU Tar.
  4. GNU Tar 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. GNU Tar is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Tar; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. /* AIX requires this to be the first thing in the file. */
  16. #ifdef __GNUC__
  17. #define alloca __builtin_alloca
  18. #else /* not __GNUC__ */
  19. #if HAVE_ALLOCA_H
  20. #include <alloca.h>
  21. #else /* not HAVE_ALLOCA_H */
  22. #ifdef _AIX
  23. #pragma alloca
  24. #else /* not _AIX */
  25. char *alloca ();
  26. #endif /* not _AIX */
  27. #endif /* not HAVE_ALLOCA_H */
  28. #endif /* not __GNUC__ */
  29. #include "pathmax.h"
  30. #ifdef _POSIX_VERSION
  31. #include <sys/wait.h>
  32. #else /* !_POSIX_VERSION */
  33. #define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
  34. #define WIFSIGNALED(w) (((w) & 0xff) != 0x7f && ((w) & 0xff) != 0)
  35. #define WIFEXITED(w) (((w) & 0xff) == 0)
  36. #define WSTOPSIG(w) (((w) >> 8) & 0xff)
  37. #define WTERMSIG(w) ((w) & 0x7f)
  38. #define WEXITSTATUS(w) (((w) >> 8) & 0xff)
  39. #endif /* _POSIX_VERSION */
  40. /* nonstandard */
  41. #ifndef WIFCOREDUMPED
  42. #define WIFCOREDUMPED(w) (((w) & 0x80) != 0)
  43. #endif
  44. #ifdef __MSDOS__
  45. /* missing things from sys/stat.h */
  46. #define S_ISUID 0
  47. #define S_ISGID 0
  48. #define S_ISVTX 0
  49. /* device stuff */
  50. #define makedev(ma, mi) ((ma << 8) | mi)
  51. #define major(dev) (dev)
  52. #define minor(dev) (dev)
  53. typedef long off_t;
  54. #endif /* __MSDOS__ */
  55. #if defined(__STDC__) || defined(__TURBOC__)
  56. #define PTR void *
  57. #else
  58. #define PTR char *
  59. #define const
  60. #endif
  61. /* Since major is a function on SVR4, we can't just use `ifndef major'. */
  62. #ifdef major /* Might be defined in sys/types.h. */
  63. #define HAVE_MAJOR
  64. #endif
  65. #if !defined(HAVE_MAJOR) && defined(MAJOR_IN_MKDEV)
  66. #include <sys/mkdev.h>
  67. #define HAVE_MAJOR
  68. #endif
  69. #if !defined(HAVE_MAJOR) && defined(MAJOR_IN_SYSMACROS)
  70. #include <sys/sysmacros.h>
  71. #define HAVE_MAJOR
  72. #endif
  73. #ifndef HAVE_MAJOR
  74. #define major(dev) (((dev) >> 8) & 0xff)
  75. #define minor(dev) ((dev) & 0xff)
  76. #define makedev(maj, min) (((maj) << 8) | (min))
  77. #endif
  78. #undef HAVE_MAJOR
  79. #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
  80. #include <string.h>
  81. #if !defined(__MSDOS__) && !defined(STDC_HEADERS)
  82. #include <memory.h>
  83. #endif
  84. #ifdef index
  85. #undef index
  86. #endif
  87. #ifdef rindex
  88. #undef rindex
  89. #endif
  90. #define index strchr
  91. #define rindex strrchr
  92. #define bcopy(s, d, n) memcpy(d, s, n)
  93. #define bzero(s, n) memset(s, 0, n)
  94. #define bcmp memcmp
  95. #else
  96. #include <strings.h>
  97. #endif
  98. #if defined(STDC_HEADERS)
  99. #include <stdlib.h>
  100. #else
  101. char *malloc (), *realloc ();
  102. char *getenv ();
  103. #endif
  104. #ifndef _POSIX_VERSION
  105. #ifdef __MSDOS__
  106. #include <io.h>
  107. #else /* !__MSDOS__ */
  108. off_t lseek ();
  109. #endif /* !__MSDOS__ */
  110. char *getcwd ();
  111. #endif /* !_POSIX_VERSION */
  112. #ifndef NULL
  113. #define NULL 0
  114. #endif
  115. #ifndef O_BINARY
  116. #define O_BINARY 0
  117. #endif
  118. #ifndef O_CREAT
  119. #define O_CREAT 0
  120. #endif
  121. #ifndef O_NDELAY
  122. #define O_NDELAY 0
  123. #endif
  124. #ifndef O_RDONLY
  125. #define O_RDONLY 0
  126. #endif
  127. #ifndef O_RDWR
  128. #define O_RDWR 2
  129. #endif
  130. #include <sys/stat.h>
  131. #ifndef S_ISREG /* Doesn't have POSIX.1 stat stuff. */
  132. #define mode_t unsigned short
  133. #endif
  134. #if !defined(S_ISBLK) && defined(S_IFBLK)
  135. #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  136. #endif
  137. #if !defined(S_ISCHR) && defined(S_IFCHR)
  138. #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  139. #endif
  140. #if !defined(S_ISDIR) && defined(S_IFDIR)
  141. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  142. #endif
  143. #if !defined(S_ISREG) && defined(S_IFREG)
  144. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  145. #endif
  146. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  147. #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  148. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  149. #endif
  150. #if !defined(S_ISLNK) && defined(S_IFLNK)
  151. #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  152. #endif
  153. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  154. #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  155. #endif
  156. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  157. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  158. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  159. #endif
  160. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  161. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  162. #endif
  163. #if !defined(S_ISCTG) && defined(S_IFCTG) /* contiguous file */
  164. #define S_ISCTG(m) (((m) & S_IFMT) == S_IFCTG)
  165. #endif
  166. #if !defined(S_ISVTX)
  167. #define S_ISVTX 0001000
  168. #endif
  169. #ifdef __MSDOS__
  170. #include "msd_dir.h"
  171. #define NLENGTH(direct) ((direct)->d_namlen)
  172. #else /* not __MSDOS__ */
  173. #if defined(DIRENT) || defined(_POSIX_VERSION)
  174. #include <dirent.h>
  175. #define NLENGTH(direct) (strlen((direct)->d_name))
  176. #else /* not (DIRENT or _POSIX_VERSION) */
  177. #define dirent direct
  178. #define NLENGTH(direct) ((direct)->d_namlen)
  179. #ifdef SYSNDIR
  180. #include <sys/ndir.h>
  181. #endif /* SYSNDIR */
  182. #ifdef SYSDIR
  183. #include <sys/dir.h>
  184. #endif /* SYSDIR */
  185. #ifdef NDIR
  186. #include <ndir.h>
  187. #endif /* NDIR */
  188. #endif /* DIRENT or _POSIX_VERSION */
  189. #endif /* not __MSDOS__ */