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