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