Merge branch 'vendor/TNFTP'
[dragonfly.git] / contrib / cvs-1.12 / 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 #include <limits.h>
184 #ifndef INT_MAX
185 #define INT_MAX 2147483647
186 #endif
187 #ifndef CHAR_BIT
188 #define CHAR_BIT 8
189 #endif
190
191 #if STDC_HEADERS || HAVE_STRING_H
192 # include <string.h>
193 # ifndef bzero
194 #  define bzero(s, n) memset (s, 0, n)
195 # endif
196 #else
197 # if !HAVE_STRCHR
198 #  define strchr index
199 #  define strrchr rindex
200 # endif
201 char *strchr (), *strrchr ();
202 # if !HAVE_MEMCHR
203 #  define memcmp(s1, s2, n) bcmp (s1, s2, n)
204 #  define memcpy(d, s, n) bcopy (s, d, n)
205 void *memchr ();
206 # endif
207 #endif
208
209 #include <ctype.h>
210 /* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
211    as an argument to <ctype.h> macros like `isspace'.  */
212 #if STDC_HEADERS
213 #define CTYPE_DOMAIN(c) 1
214 #else
215 #define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
216 #endif
217 #ifndef ISPRINT
218 #define ISPRINT(c) (CTYPE_DOMAIN (c) && isprint (c))
219 #endif
220 #ifndef ISSPACE
221 #define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
222 #endif
223 #ifndef ISUPPER
224 #define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c))
225 #endif
226
227 #ifndef ISDIGIT
228 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
229 #endif
230
231 #include <errno.h>
232 #if !STDC_HEADERS
233 extern int errno;
234 #endif
235
236 #ifdef min
237 #undef min
238 #endif
239 #ifdef max
240 #undef max
241 #endif
242 #define min(a,b) ((a) <= (b) ? (a) : (b))
243 #define max(a,b) ((a) >= (b) ? (a) : (b))
244 \f
245 /* This section contains Posix-compliant defaults for macros
246    that are meant to be overridden by hand in config.h as needed.  */
247
248 #ifndef filename_cmp
249 #define filename_cmp(a, b) strcmp (a, b)
250 #endif
251
252 #ifndef filename_lastdirchar
253 #define filename_lastdirchar(filename) strrchr (filename, '/')
254 #endif
255
256 #ifndef HAVE_FORK
257 #define HAVE_FORK 1
258 #endif
259
260 #ifndef HAVE_SETMODE
261 #define HAVE_SETMODE 0
262 #endif
263
264 #ifndef initialize_main
265 #define initialize_main(argcp, argvp)
266 #endif
267
268 /* Do struct stat *S, *T describe the same file?  Answer -1 if unknown.  */
269 #ifndef same_file
270 #define same_file(s,t) ((s)->st_ino==(t)->st_ino && (s)->st_dev==(t)->st_dev)
271 #endif
272
273 /* Place into Q a quoted version of A suitable for `popen' or `system',
274    incrementing Q and junking A.
275    Do not increment Q by more than 4 * strlen (A) + 2.  */
276 #ifndef SYSTEM_QUOTE_ARG
277 #define SYSTEM_QUOTE_ARG(q, a) \
278   { \
279     *(q)++ = '\''; \
280     for (;  *(a);  *(q)++ = *(a)++) \
281       if (*(a) == '\'') \
282         { \
283           *(q)++ = '\''; \
284           *(q)++ = '\\'; \
285           *(q)++ = '\''; \
286         } \
287     *(q)++ = '\''; \
288   }
289 #endif
290
291 /* these come from CVS's lib/system.h, but I wasn't sure how to include that
292  * properly or even if I really should
293  */
294 #ifndef CVS_OPENDIR
295 #define CVS_OPENDIR opendir
296 #endif
297 #ifndef CVS_READDIR
298 #define CVS_READDIR readdir
299 #endif
300 #ifndef CVS_CLOSEDIR
301 #define CVS_CLOSEDIR closedir
302 #endif