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