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