port.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Portability declarations. Requires sys/types.h.
  2. Copyright (C) 1988 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. #include "pathmax.h"
  16. #ifdef __GNUC__
  17. #define alloca __builtin_alloca
  18. #endif
  19. #ifdef _POSIX_VERSION
  20. #include <sys/wait.h>
  21. #else /* !_POSIX_VERSION */
  22. #define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
  23. #define WIFSIGNALED(w) (((w) & 0xff) != 0x7f && ((w) & 0xff) != 0)
  24. #define WIFEXITED(w) (((w) & 0xff) == 0)
  25. #define WSTOPSIG(w) (((w) >> 8) & 0xff)
  26. #define WTERMSIG(w) ((w) & 0x7f)
  27. #define WEXITSTATUS(w) (((w) >> 8) & 0xff)
  28. #endif /* _POSIX_VERSION */
  29. /* nonstandard */
  30. #ifndef WIFCOREDUMPED
  31. #define WIFCOREDUMPED(w) (((w) & 0x80) != 0)
  32. #endif
  33. #ifdef __MSDOS__
  34. /* missing things from sys/stat.h */
  35. #define S_ISUID 0
  36. #define S_ISGID 0
  37. #define S_ISVTX 0
  38. /* device stuff */
  39. #define makedev(ma, mi) ((ma << 8) | mi)
  40. #define major(dev) (dev)
  41. #define minor(dev) (dev)
  42. typedef long off_t;
  43. #endif /* __MSDOS__ */
  44. #if defined(__STDC__) || defined(__TURBOC__)
  45. #define PTR void *
  46. #else
  47. #define PTR char *
  48. #define const
  49. #endif
  50. /* Since major is a function on SVR4, we can't just use `ifndef major'. */
  51. #ifdef major /* Might be defined in sys/types.h. */
  52. #define HAVE_MAJOR
  53. #endif
  54. #if !defined(HAVE_MAJOR) && defined(MAJOR_IN_MKDEV)
  55. #include <sys/mkdev.h>
  56. #define HAVE_MAJOR
  57. #endif
  58. #if !defined(HAVE_MAJOR) && defined(MAJOR_IN_SYSMACROS)
  59. #include <sys/sysmacros.h>
  60. #define HAVE_MAJOR
  61. #endif
  62. #ifndef HAVE_MAJOR
  63. #define major(dev) (((dev) >> 8) & 0xff)
  64. #define minor(dev) ((dev) & 0xff)
  65. #define makedev(maj, min) (((maj) << 8) | (min))
  66. #endif
  67. #undef HAVE_MAJOR
  68. #if defined(STDC_HEADERS) || defined(USG)
  69. #include <string.h>
  70. #if !defined(__MSDOS__) && !defined(STDC_HEADERS)
  71. #include <memory.h>
  72. #endif
  73. #define index strchr
  74. #define rindex strrchr
  75. #define bcopy(s, d, n) memcpy(d, s, n)
  76. #define bzero(s, n) memset(s, 0, n)
  77. #define bcmp memcmp
  78. #else
  79. #include <strings.h>
  80. #endif
  81. #if defined(STDC_HEADERS)
  82. #include <stdlib.h>
  83. #else
  84. char *malloc(), *realloc();
  85. char *getenv();
  86. #endif
  87. #ifndef _POSIX_VERSION
  88. #ifdef __MSDOS__
  89. #include <io.h>
  90. #else /* !__MSDOS__ */
  91. off_t lseek();
  92. #endif /* !__MSDOS__ */
  93. char *getcwd();
  94. #endif /* !_POSIX_VERSION */
  95. #ifndef NULL
  96. #define NULL 0
  97. #endif
  98. #ifndef O_BINARY
  99. #define O_BINARY 0
  100. #endif
  101. #ifndef O_CREAT
  102. #define O_CREAT 0
  103. #endif
  104. #ifndef O_NDELAY
  105. #define O_NDELAY 0
  106. #endif
  107. #ifndef O_RDONLY
  108. #define O_RDONLY 0
  109. #endif
  110. #ifndef O_RDWR
  111. #define O_RDWR 2
  112. #endif
  113. #include <sys/stat.h>
  114. #ifndef S_ISREG /* Doesn't have POSIX.1 stat stuff. */
  115. #define mode_t unsigned short
  116. #endif
  117. #if !defined(S_ISBLK) && defined(S_IFBLK)
  118. #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  119. #endif
  120. #if !defined(S_ISCHR) && defined(S_IFCHR)
  121. #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  122. #endif
  123. #if !defined(S_ISDIR) && defined(S_IFDIR)
  124. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  125. #endif
  126. #if !defined(S_ISREG) && defined(S_IFREG)
  127. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  128. #endif
  129. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  130. #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  131. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  132. #endif
  133. #if !defined(S_ISLNK) && defined(S_IFLNK)
  134. #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  135. #endif
  136. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  137. #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  138. #endif
  139. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  140. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  141. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  142. #endif
  143. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  144. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  145. #endif
  146. #if !defined(S_ISCTG) && defined(S_IFCTG) /* contiguous file */
  147. #define S_ISCTG(m) (((m) & S_IFMT) == S_IFCTG)
  148. #endif
  149. #if !defined(S_ISVTX)
  150. #define S_ISVTX 0001000
  151. #endif