usr.sbin/makefs: Add -o c|C option to specify comp|check type
[dragonfly.git] / contrib / cvs-1.12 / lib / system.h
blob8ea4a95dfce912b77ba83390a0db834ff009eca9
1 /* system-dependent definitions for CVS.
2 Copyright (C) 1989-1992 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. */
14 /***
15 *** Begin the default set of autoconf includes.
16 ***/
18 /* Headers assumed for C89 freestanding compilers. See HACKING for more. */
19 #include <limits.h>
20 #include <stdarg.h>
21 #include <stddef.h>
23 /* C89 hosted headers assumed since they were included in UNIX version 7.
24 * See HACKING for more.
26 #include <assert.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <signal.h>
30 #include <stdio.h>
32 /* C89 hosted headers we _think_ GCC supplies even on freestanding systems.
33 * If we find any systems which do not have them, a replacement header should
34 * be discussed with the GNULIB folks.
36 * For more information, please see the `Portability' section of the `HACKING'
37 * file.
39 #include <stdlib.h>
40 #include <string.h>
42 /* We assume this because it has been around forever despite not being a part
43 * of any of the other standards we assume conformance to. So far this hasn't
44 * been a problem.
46 * For more information, please see the `Portability' section of the `HACKING'
47 * file.
49 #include <sys/types.h>
51 /* A GNULIB replacement for this C99 header is supplied when it is missing.
52 * See the comments in stdbool_.h for its limitations.
54 #include <stdbool.h>
56 /* Ditto for these POSIX.2 headers. */
57 #include <fnmatch.h>
58 #include <getopt.h> /* Has GNU extensions, */
60 /* We assume <sys/stat.h> because GNULIB does. */
61 #include <sys/stat.h>
63 #if !STDC_HEADERS && HAVE_MEMORY_H
64 # include <memory.h>
65 #endif /* !STDC_HEADERS && HAVE_MEMORY_H */
66 #if HAVE_INTTYPES_H
67 # include <inttypes.h>
68 #else /* ! HAVE_INTTYPES_H */
69 # if HAVE_STDINT_H
70 # include <stdint.h>
71 # endif /* HAVE_STDINT_H */
72 #endif /* HAVE_INTTYPES_H */
73 #if HAVE_UNISTD_H
74 # include <unistd.h>
75 #endif /* HAVE_UNISTD_H */
76 /* End the default set of autoconf includes */
78 /* Assume these headers. */
79 #include <pwd.h>
81 /* There is a replacement stub for gettext provided by GNULIB when gettext is
82 * not available.
84 #include <gettext.h>
86 #ifndef DEVNULL
87 # define DEVNULL "/dev/null"
88 #endif
90 #ifdef HAVE_IO_H
91 #include <io.h>
92 #endif
94 #ifdef HAVE_DIRECT_H
95 #include <direct.h>
96 #endif
98 /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h
99 which doesn't define anything. It would be cleaner to have configure
100 check for struct utimbuf, but for now I'm checking NeXT here (so I don't
101 have to debug the configure check across all the machines). */
102 #if defined (HAVE_UTIME_H) && !defined (NeXT)
103 # include <utime.h>
104 #else
105 # if defined (HAVE_SYS_UTIME_H)
106 # include <sys/utime.h>
107 # else
108 # ifndef ALTOS
109 struct utimbuf
111 long actime;
112 long modtime;
114 # endif
115 int utime ();
116 # endif
117 #endif
119 /* errno.h variations:
121 * Not all systems set the same error code on a non-existent-file
122 * error. This tries to ask the question somewhat portably.
123 * On systems that don't have ENOTEXIST, this should behave just like
124 * x == ENOENT. "x" is probably errno, of course.
126 #ifdef ENOTEXIST
127 # ifdef EOS2ERR
128 # define existence_error(x) \
129 (((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
130 # else
131 # define existence_error(x) \
132 (((x) == ENOTEXIST) || ((x) == ENOENT))
133 # endif
134 #else
135 # ifdef EVMSERR
136 # define existence_error(x) \
137 ((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
138 # else
139 # define existence_error(x) ((x) == ENOENT)
140 # endif
141 #endif
143 /* check for POSIX signals */
144 #if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
145 # define POSIX_SIGNALS
146 #endif
148 /* MINIX 1.6 doesn't properly support sigaction */
149 #if defined(_MINIX)
150 # undef POSIX_SIGNALS
151 #endif
153 /* If !POSIX, try for BSD.. Reason: 4.4BSD implements these as wrappers */
154 #if !defined(POSIX_SIGNALS)
155 # if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
156 # define BSD_SIGNALS
157 # endif
158 #endif
160 /* Under OS/2, this must be included _after_ stdio.h; that's why we do
161 it here. */
162 #ifdef USE_OWN_TCPIP_H
163 # include "tcpip.h"
164 #endif
166 #ifdef HAVE_FCNTL_H
167 # include <fcntl.h>
168 #else
169 # include <sys/file.h>
170 #endif
172 #ifndef SEEK_SET
173 # define SEEK_SET 0
174 # define SEEK_CUR 1
175 # define SEEK_END 2
176 #endif
178 #ifndef F_OK
179 # define F_OK 0
180 # define X_OK 1
181 # define W_OK 2
182 # define R_OK 4
183 #endif
185 #if HAVE_DIRENT_H
186 # include <dirent.h>
187 # define NAMLEN(dirent) strlen((dirent)->d_name)
188 #else
189 # define dirent direct
190 # define NAMLEN(dirent) (dirent)->d_namlen
191 # if HAVE_SYS_NDIR_H
192 # include <sys/ndir.h>
193 # endif
194 # if HAVE_SYS_DIR_H
195 # include <sys/dir.h>
196 # endif
197 # if HAVE_NDIR_H
198 # include <ndir.h>
199 # endif
200 #endif
202 /* Convert B 512-byte blocks to kilobytes if K is nonzero,
203 otherwise return it unchanged. */
204 #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
206 /* Under non-UNIX operating systems (MS-DOS, WinNT, MacOS), many filesystem
207 calls take only one argument; permission is handled very differently on
208 those systems than in Unix. So we leave such systems a hook on which they
209 can hang their own definitions. */
211 #ifndef CVS_ACCESS
212 # define CVS_ACCESS access
213 #endif
215 #ifndef CVS_CHDIR
216 # define CVS_CHDIR chdir
217 #endif
219 #ifndef CVS_CREAT
220 # define CVS_CREAT creat
221 #endif
223 #ifndef CVS_FOPEN
224 # define CVS_FOPEN fopen
225 #endif
227 #ifndef CVS_FDOPEN
228 # define CVS_FDOPEN fdopen
229 #endif
231 #ifndef CVS_MKDIR
232 # define CVS_MKDIR mkdir
233 #endif
235 #ifndef CVS_OPEN
236 # define CVS_OPEN open
237 #endif
239 #ifndef CVS_READDIR
240 # define CVS_READDIR readdir
241 #endif
243 #ifndef CVS_CLOSEDIR
244 # define CVS_CLOSEDIR closedir
245 #endif
247 #ifndef CVS_OPENDIR
248 # define CVS_OPENDIR opendir
249 #endif
251 #ifndef CVS_RENAME
252 # define CVS_RENAME rename
253 #endif
255 #ifndef CVS_RMDIR
256 # define CVS_RMDIR rmdir
257 #endif
259 #ifndef CVS_UNLINK
260 # define CVS_UNLINK unlink
261 #endif
263 /* Wildcard matcher. Should be case-insensitive if the system is. */
264 #ifndef CVS_FNMATCH
265 # define CVS_FNMATCH fnmatch
266 #endif
268 #ifndef HAVE_FSEEKO
269 off_t ftello (FILE *);
270 int fseeko (FILE *, off_t, int);
271 #endif /* HAVE_FSEEKO */
273 #ifdef FILENAMES_CASE_INSENSITIVE
275 # if defined (__CYGWIN32__) || defined (WOE32)
276 /* Under Windows, filenames are case-insensitive, and both / and \
277 are path component separators. */
278 # define FOLD_FN_CHAR(c) (WNT_filename_classes[(unsigned char) (c)])
279 extern unsigned char WNT_filename_classes[];
280 # else /* !__CYGWIN32__ && !WOE32 */
281 /* As far as I know, only Macintosh OS X & VMS make it here, but any
282 * platform defining FILENAMES_CASE_INSENSITIVE which isn't WOE32 or
283 * piggy-backing the same could, in theory. Since the OS X fold just folds
284 * A-Z into a-z, I'm just allowing it to be used for any case insensitive
285 * system which we aren't yet making other specific folds or exceptions for.
286 * WOE32 needs its own class since \ and C:\ style absolute paths also need
287 * to be accounted for.
289 # define FOLD_FN_CHAR(c) (OSX_filename_classes[(unsigned char) (c)])
290 extern unsigned char OSX_filename_classes[];
291 # endif /* __CYGWIN32__ || WOE32 */
293 /* The following need to be declared for all case insensitive filesystems.
294 * When not FOLD_FN_CHAR is not #defined, a default definition for these
295 * functions is provided later in this header file. */
297 /* Like strcmp, but with the appropriate tweaks for file names. */
298 extern int fncmp (const char *n1, const char *n2);
300 /* Fold characters in FILENAME to their canonical forms. */
301 extern void fnfold (char *FILENAME);
303 #endif /* FILENAMES_CASE_INSENSITIVE */
307 /* Some file systems are case-insensitive. If FOLD_FN_CHAR is
308 #defined, it maps the character C onto its "canonical" form. In a
309 case-insensitive system, it would map all alphanumeric characters
310 to lower case. Under Windows NT, / and \ are both path component
311 separators, so FOLD_FN_CHAR would map them both to /. */
312 #ifndef FOLD_FN_CHAR
313 # define FOLD_FN_CHAR(c) (c)
314 # define fnfold(filename) (filename)
315 # define fncmp strcmp
316 #endif
318 /* Different file systems can have different naming patterns which designate
319 * a path as absolute.
321 #ifndef ISABSOLUTE
322 # define ISABSOLUTE(s) ISSLASH(s[FILE_SYSTEM_PREFIX_LEN(s)])
323 #endif
326 /* On some systems, we have to be careful about writing/reading files
327 in text or binary mode (so in text mode the system can handle CRLF
328 vs. LF, VMS text file conventions, &c). We decide to just always
329 be careful. That way we don't have to worry about whether text and
330 binary differ on this system. We just have to worry about whether
331 the system has O_BINARY and "rb". The latter is easy; all ANSI C
332 libraries have it, SunOS4 has it, and CVS has used it unguarded
333 some places for a while now without complaints (e.g. "rb" in
334 server.c (server_updated), since CVS 1.8). The former is just an
335 #ifdef. */
337 #define FOPEN_BINARY_READ ("rb")
338 #define FOPEN_BINARY_WRITE ("wb")
339 #define FOPEN_BINARY_READWRITE ("r+b")
341 #ifdef O_BINARY
342 #define OPEN_BINARY (O_BINARY)
343 #else
344 #define OPEN_BINARY (0)
345 #endif
347 #ifndef fd_select
348 # define fd_select select
349 #endif