common.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* common definitions for `patch' */
  2. /* $Id: common.h,v 1.18 1997/06/13 06:28:37 eggert Exp $ */
  3. /*
  4. Copyright 1986, 1988 Larry Wall
  5. Copyright 1990, 1991, 1992, 1993, 1997 Free Software Foundation, Inc.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. See the GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING.
  16. If not, write to the Free Software Foundation,
  17. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #ifndef DEBUGGING
  20. #define DEBUGGING 1
  21. #endif
  22. /* We must define `volatile' and `const' first (the latter inside config.h),
  23. so that they're used consistently in all system includes. */
  24. #ifndef __STDC__
  25. # ifndef volatile
  26. # define volatile
  27. # endif
  28. #endif
  29. /* Enable support for fseeko and ftello on hosts
  30. where it is available but is turned off by default.
  31. This must be defined before any system file is included. */
  32. #define _LARGEFILE_SOURCE 1
  33. #include <config.h>
  34. #include <assert.h>
  35. #include <stdio.h>
  36. #include <sys/types.h>
  37. #include <time.h>
  38. #include <sys/stat.h>
  39. #if ! defined S_ISDIR && defined S_IFDIR
  40. # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  41. #endif
  42. #if ! defined S_ISREG && defined S_IFREG
  43. # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  44. #endif
  45. #ifndef S_IXOTH
  46. #define S_IXOTH 1
  47. #endif
  48. #ifndef S_IWOTH
  49. #define S_IWOTH 2
  50. #endif
  51. #ifndef S_IROTH
  52. #define S_IROTH 4
  53. #endif
  54. #ifndef S_IXGRP
  55. #define S_IXGRP (S_IXOTH << 3)
  56. #endif
  57. #ifndef S_IWGRP
  58. #define S_IWGRP (S_IWOTH << 3)
  59. #endif
  60. #ifndef S_IRGRP
  61. #define S_IRGRP (S_IROTH << 3)
  62. #endif
  63. #ifndef S_IXUSR
  64. #define S_IXUSR (S_IXOTH << 6)
  65. #endif
  66. #ifndef S_IWUSR
  67. #define S_IWUSR (S_IWOTH << 6)
  68. #endif
  69. #ifndef S_IRUSR
  70. #define S_IRUSR (S_IROTH << 6)
  71. #endif
  72. #if HAVE_LIMITS_H
  73. # include <limits.h>
  74. #endif
  75. #ifndef INT_MAX
  76. #define INT_MAX 2147483647
  77. #endif
  78. #ifndef LONG_MIN
  79. #define LONG_MIN (-1-2147483647L)
  80. #endif
  81. #include <ctype.h>
  82. /* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
  83. as an argument to <ctype.h> macros like `isspace'. */
  84. #if STDC_HEADERS
  85. #define CTYPE_DOMAIN(c) 1
  86. #else
  87. #define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
  88. #endif
  89. #ifndef ISSPACE
  90. #define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
  91. #endif
  92. #ifndef ISDIGIT
  93. #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
  94. #endif
  95. #ifndef FILESYSTEM_PREFIX_LEN
  96. #define FILESYSTEM_PREFIX_LEN(f) 0
  97. #endif
  98. #ifndef ISSLASH
  99. #define ISSLASH(c) ((c) == '/')
  100. #endif
  101. /* constants */
  102. /* AIX predefines these. */
  103. #ifdef TRUE
  104. #undef TRUE
  105. #endif
  106. #ifdef FALSE
  107. #undef FALSE
  108. #endif
  109. #define TRUE 1
  110. #define FALSE 0
  111. /* handy definitions */
  112. #define strEQ(s1,s2) (!strcmp(s1, s2))
  113. #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
  114. /* typedefs */
  115. typedef int bool; /* must promote to itself */
  116. typedef long LINENUM; /* must be signed */
  117. /* globals */
  118. extern char const program_name[];
  119. XTERN char *buf; /* general purpose buffer */
  120. XTERN size_t bufsize; /* allocated size of buf */
  121. XTERN bool using_plan_a; /* try to keep everything in memory */
  122. XTERN char *inname;
  123. XTERN char *outfile;
  124. XTERN int inerrno;
  125. XTERN int invc;
  126. XTERN struct stat instat;
  127. XTERN bool dry_run;
  128. XTERN bool posixly_correct;
  129. XTERN char const *origprae;
  130. XTERN char const *origbase;
  131. XTERN char const * volatile TMPOUTNAME;
  132. XTERN char const * volatile TMPINNAME;
  133. XTERN char const * volatile TMPPATNAME;
  134. #ifdef DEBUGGING
  135. XTERN int debug;
  136. #else
  137. # define debug 0
  138. #endif
  139. XTERN bool force;
  140. XTERN bool batch;
  141. XTERN bool noreverse;
  142. XTERN int reverse;
  143. XTERN enum { DEFAULT_VERBOSITY, SILENT, VERBOSE } verbosity;
  144. XTERN bool skip_rest_of_patch;
  145. XTERN int strippath;
  146. XTERN bool canonicalize;
  147. XTERN int patch_get;
  148. XTERN int set_time;
  149. XTERN int set_utc;
  150. enum diff
  151. {
  152. NO_DIFF,
  153. CONTEXT_DIFF,
  154. NORMAL_DIFF,
  155. ED_DIFF,
  156. NEW_CONTEXT_DIFF,
  157. UNI_DIFF
  158. };
  159. XTERN enum diff diff_type;
  160. XTERN char *revision; /* prerequisite revision, if any */
  161. #ifdef __STDC__
  162. # define GENERIC_OBJECT void
  163. #else
  164. # define GENERIC_OBJECT char
  165. #endif
  166. #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
  167. # define __attribute__(x)
  168. #endif
  169. #ifndef PARAMS
  170. # ifdef __STDC__
  171. # define PARAMS(args) args
  172. # else
  173. # define PARAMS(args) ()
  174. # endif
  175. #endif
  176. GENERIC_OBJECT *xmalloc PARAMS ((size_t));
  177. void fatal_exit PARAMS ((int)) __attribute__ ((noreturn));
  178. #include <errno.h>
  179. #if !STDC_HEADERS && !defined errno
  180. extern int errno;
  181. #endif
  182. #if STDC_HEADERS || HAVE_STRING_H
  183. # include <string.h>
  184. #else
  185. # if !HAVE_MEMCHR
  186. # define memcmp(s1, s2, n) bcmp (s1, s2, n)
  187. # define memcpy(d, s, n) bcopy (s, d, n)
  188. GENERIC_OBJECT *memchr ();
  189. # endif
  190. #endif
  191. #if STDC_HEADERS
  192. # include <stdlib.h>
  193. #else
  194. long atol ();
  195. char *getenv ();
  196. GENERIC_OBJECT *malloc ();
  197. GENERIC_OBJECT *realloc ();
  198. #endif
  199. #if HAVE_UNISTD_H
  200. # include <unistd.h>
  201. #endif
  202. #ifndef lseek
  203. off_t lseek ();
  204. #endif
  205. #ifndef SEEK_SET
  206. #define SEEK_SET 0
  207. #endif
  208. #ifndef STDIN_FILENO
  209. #define STDIN_FILENO 0
  210. #endif
  211. #ifndef STDOUT_FILENO
  212. #define STDOUT_FILENO 1
  213. #endif
  214. #ifndef STDERR_FILENO
  215. #define STDERR_FILENO 2
  216. #endif
  217. #if _LFS_LARGEFILE
  218. typedef off_t file_offset;
  219. # define file_seek fseeko
  220. # define file_tell ftello
  221. #else
  222. typedef long file_offset;
  223. # define file_seek fseek
  224. # define file_tell ftell
  225. #endif
  226. #if HAVE_FCNTL_H
  227. # include <fcntl.h>
  228. #endif
  229. #ifndef O_RDONLY
  230. #define O_RDONLY 0
  231. #endif
  232. #ifndef O_WRONLY
  233. #define O_WRONLY 1
  234. #endif
  235. #ifndef O_RDWR
  236. #define O_RDWR 2
  237. #endif
  238. #ifndef _O_BINARY
  239. #define _O_BINARY 0
  240. #endif
  241. #ifndef O_BINARY
  242. #define O_BINARY _O_BINARY
  243. #endif
  244. #ifndef O_CREAT
  245. #define O_CREAT 0
  246. #endif
  247. #ifndef O_TRUNC
  248. #define O_TRUNC 0
  249. #endif
  250. #if HAVE_SETMODE
  251. XTERN int binary_transput; /* O_BINARY if binary i/o is desired */
  252. #else
  253. # define binary_transput 0
  254. #endif
  255. #ifndef NULL_DEVICE
  256. #define NULL_DEVICE "/dev/null"
  257. #endif
  258. #ifndef TTY_DEVICE
  259. #define TTY_DEVICE "/dev/tty"
  260. #endif