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