/contrib/cvs/diff/system.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 304 lines · 233 code · 33 blank · 38 comment · 25 complexity · 31f002732f6f192203ea3758ce65df03 MD5 · raw file

  1. /* System dependent declarations.
  2. Copyright (C) 1988, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
  3. This file is part of GNU DIFF.
  4. GNU DIFF 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 DIFF 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. */
  13. /* We must define `volatile' and `const' first (the latter inside config.h),
  14. so that they're used consistently in all system includes. */
  15. #if !__STDC__
  16. #ifndef volatile
  17. #define volatile
  18. #endif
  19. #endif
  20. #include <config.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. /* Note that PARAMS is just internal to the diff library; diffrun.h
  24. has its own mechanism, which will hopefully be less likely to
  25. conflict with the library's caller's namespace. */
  26. #if __STDC__
  27. #define PARAMS(args) args
  28. #define VOID void
  29. #else
  30. #define PARAMS(args) ()
  31. #define VOID char
  32. #endif
  33. #if STAT_MACROS_BROKEN
  34. #undef S_ISBLK
  35. #undef S_ISCHR
  36. #undef S_ISDIR
  37. #undef S_ISFIFO
  38. #undef S_ISREG
  39. #undef S_ISSOCK
  40. #endif
  41. #ifndef S_ISDIR
  42. #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
  43. #endif
  44. #ifndef S_ISREG
  45. #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
  46. #endif
  47. #if !defined(S_ISBLK) && defined(S_IFBLK)
  48. #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
  49. #endif
  50. #if !defined(S_ISCHR) && defined(S_IFCHR)
  51. #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
  52. #endif
  53. #if !defined(S_ISFIFO) && defined(S_IFFIFO)
  54. #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO)
  55. #endif
  56. #ifndef S_ISSOCK
  57. # if defined( S_IFSOCK )
  58. # ifdef S_IFMT
  59. # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
  60. # else
  61. # define S_ISSOCK(mode) ((mode) & S_IFSOCK)
  62. # endif /* S_IFMT */
  63. # elif defined( S_ISNAM )
  64. /* SCO OpenServer 5.0.6a */
  65. # define S_ISSOCK S_ISNAM
  66. # endif /* !S_IFSOCK && S_ISNAM */
  67. #endif /* !S_ISSOCK */
  68. #if HAVE_UNISTD_H
  69. #include <unistd.h>
  70. #endif
  71. #ifdef HAVE_IO_H
  72. # include <io.h>
  73. #endif
  74. #ifdef HAVE_FCNTL_H
  75. # include <fcntl.h>
  76. #else
  77. # include <sys/file.h>
  78. #endif
  79. #ifndef SEEK_SET
  80. #define SEEK_SET 0
  81. #endif
  82. #ifndef SEEK_CUR
  83. #define SEEK_CUR 1
  84. #endif
  85. #ifndef STDIN_FILENO
  86. #define STDIN_FILENO 0
  87. #endif
  88. #ifndef STDOUT_FILENO
  89. #define STDOUT_FILENO 1
  90. #endif
  91. #ifndef STDERR_FILENO
  92. #define STDERR_FILENO 2
  93. #endif
  94. /* I believe that all relevant systems have
  95. time.h. It is in ANSI, for example. The
  96. code below looks quite bogus as I don't think
  97. sys/time.h is ever a substitute for time.h;
  98. it is something different. */
  99. #define HAVE_TIME_H 1
  100. #if HAVE_TIME_H
  101. #include <time.h>
  102. #else
  103. #include <sys/time.h>
  104. #endif
  105. #if HAVE_FCNTL_H
  106. #include <fcntl.h>
  107. #else
  108. #if HAVE_SYS_FILE_H
  109. #include <sys/file.h>
  110. #endif
  111. #endif
  112. #ifndef O_RDONLY
  113. #define O_RDONLY 0
  114. #endif
  115. #if HAVE_SYS_WAIT_H
  116. #include <sys/wait.h>
  117. #endif
  118. #ifndef WEXITSTATUS
  119. #define WEXITSTATUS(stat_val) ((unsigned) (stat_val) >> 8)
  120. #endif
  121. #ifndef WIFEXITED
  122. #define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
  123. #endif
  124. #ifndef STAT_BLOCKSIZE
  125. #if HAVE_STRUCT_STAT_ST_BLKSIZE
  126. #define STAT_BLOCKSIZE(s) (s).st_blksize
  127. #else
  128. #define STAT_BLOCKSIZE(s) (8 * 1024)
  129. #endif
  130. #endif
  131. #if HAVE_DIRENT_H
  132. # include <dirent.h>
  133. # define NAMLEN(dirent) strlen((dirent)->d_name)
  134. #else
  135. # define dirent direct
  136. # define NAMLEN(dirent) ((dirent)->d_namlen)
  137. # if HAVE_SYS_NDIR_H
  138. # include <sys/ndir.h>
  139. # endif
  140. # if HAVE_SYS_DIR_H
  141. # include <sys/dir.h>
  142. # endif
  143. # if HAVE_NDIR_H
  144. # include <ndir.h>
  145. # endif
  146. #endif
  147. #if HAVE_VFORK_H
  148. #include <vfork.h>
  149. #endif
  150. #if HAVE_STDLIB_H || defined(STDC_HEADERS)
  151. #include <stdlib.h>
  152. #else
  153. VOID *malloc ();
  154. VOID *realloc ();
  155. #endif
  156. #ifndef getenv
  157. char *getenv ();
  158. #endif
  159. #if HAVE_LIMITS_H
  160. #include <limits.h>
  161. #endif
  162. #ifndef INT_MAX
  163. #define INT_MAX 2147483647
  164. #endif
  165. #ifndef CHAR_BIT
  166. #define CHAR_BIT 8
  167. #endif
  168. #if STDC_HEADERS || HAVE_STRING_H
  169. # include <string.h>
  170. # ifndef bzero
  171. # define bzero(s, n) memset (s, 0, n)
  172. # endif
  173. #else
  174. # if !HAVE_STRCHR
  175. # define strchr index
  176. # define strrchr rindex
  177. # endif
  178. char *strchr (), *strrchr ();
  179. # if !HAVE_MEMCHR
  180. # define memcmp(s1, s2, n) bcmp (s1, s2, n)
  181. # define memcpy(d, s, n) bcopy (s, d, n)
  182. void *memchr ();
  183. # endif
  184. #endif
  185. #include <ctype.h>
  186. /* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
  187. as an argument to <ctype.h> macros like `isspace'. */
  188. #if STDC_HEADERS
  189. #define CTYPE_DOMAIN(c) 1
  190. #else
  191. #define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
  192. #endif
  193. #ifndef ISPRINT
  194. #define ISPRINT(c) (CTYPE_DOMAIN (c) && isprint (c))
  195. #endif
  196. #ifndef ISSPACE
  197. #define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
  198. #endif
  199. #ifndef ISUPPER
  200. #define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c))
  201. #endif
  202. #ifndef ISDIGIT
  203. #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
  204. #endif
  205. #include <errno.h>
  206. #if !STDC_HEADERS
  207. extern int errno;
  208. #endif
  209. #ifdef min
  210. #undef min
  211. #endif
  212. #ifdef max
  213. #undef max
  214. #endif
  215. #define min(a,b) ((a) <= (b) ? (a) : (b))
  216. #define max(a,b) ((a) >= (b) ? (a) : (b))
  217. /* This section contains Posix-compliant defaults for macros
  218. that are meant to be overridden by hand in config.h as needed. */
  219. #ifndef filename_cmp
  220. #define filename_cmp(a, b) strcmp (a, b)
  221. #endif
  222. #ifndef filename_lastdirchar
  223. #define filename_lastdirchar(filename) strrchr (filename, '/')
  224. #endif
  225. #ifndef HAVE_FORK
  226. #define HAVE_FORK 1
  227. #endif
  228. #ifndef HAVE_SETMODE
  229. #define HAVE_SETMODE 0
  230. #endif
  231. #ifndef initialize_main
  232. #define initialize_main(argcp, argvp)
  233. #endif
  234. /* Do struct stat *S, *T describe the same file? Answer -1 if unknown. */
  235. #ifndef same_file
  236. #define same_file(s,t) ((s)->st_ino==(t)->st_ino && (s)->st_dev==(t)->st_dev)
  237. #endif
  238. /* Place into Q a quoted version of A suitable for `popen' or `system',
  239. incrementing Q and junking A.
  240. Do not increment Q by more than 4 * strlen (A) + 2. */
  241. #ifndef SYSTEM_QUOTE_ARG
  242. #define SYSTEM_QUOTE_ARG(q, a) \
  243. { \
  244. *(q)++ = '\''; \
  245. for (; *(a); *(q)++ = *(a)++) \
  246. if (*(a) == '\'') \
  247. { \
  248. *(q)++ = '\''; \
  249. *(q)++ = '\\'; \
  250. *(q)++ = '\''; \
  251. } \
  252. *(q)++ = '\''; \
  253. }
  254. #endif
  255. /* these come from CVS's lib/system.h, but I wasn't sure how to include that
  256. * properly or even if I really should
  257. */
  258. #ifndef CVS_OPENDIR
  259. #define CVS_OPENDIR opendir
  260. #endif
  261. #ifndef CVS_READDIR
  262. #define CVS_READDIR readdir
  263. #endif
  264. #ifndef CVS_CLOSEDIR
  265. #define CVS_CLOSEDIR closedir
  266. #endif