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)
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. */
15 *** Begin the default set of autoconf includes.
18 /* Headers assumed for C89 freestanding compilers. See HACKING for more. */
23 /* C89 hosted headers assumed since they were included in UNIX version 7.
24 * See HACKING for more.
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'
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
46 * For more information, please see the `Portability' section of the `HACKING'
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.
56 /* Ditto for these POSIX.2 headers. */
58 #include <getopt.h> /* Has GNU extensions, */
63 # include <sys/stat.h>
64 #endif /* HAVE_SYS_STAT_H */
65 #if !STDC_HEADERS && HAVE_MEMORY_H
67 #endif /* !STDC_HEADERS && HAVE_MEMORY_H */
69 # include <inttypes.h>
70 #else /* ! HAVE_INTTYPES_H */
73 # endif /* HAVE_STDINT_H */
74 #endif /* HAVE_INTTYPES_H */
77 #endif /* HAVE_UNISTD_H */
78 /* End the default set of autoconf includes */
80 /* Assume these headers. */
83 /* More GNULIB includes */
84 /* This include enables the use of the *_unlocked IO functions from glibc. */
85 #include "unlocked-io.h"
87 /* For struct timespec. */
90 /* This is a replacement stub for gettext provided by GNULIB when gettext is
94 /* End GNULIB includes */
96 #ifdef STAT_MACROS_BROKEN
109 /* Not all systems have S_IFMT, but we want to use it if we have it.
110 The S_IFMT code below looks right (it masks and compares). The
111 non-S_IFMT code looks bogus (are there really systems on which
112 S_IFBLK, S_IFLNK, &c, each have their own bit? I suspect it was
113 written for OS/2 using the IBM C/C++ Tools 2.01 compiler).
115 Of course POSIX systems will have S_IS*, so maybe the issue is
118 #if !defined(S_ISBLK) && defined(S_IFBLK)
120 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
122 # define S_ISBLK(m) ((m) & S_IFBLK)
126 #if !defined(S_ISCHR) && defined(S_IFCHR)
128 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
130 # define S_ISCHR(m) ((m) & S_IFCHR)
134 #if !defined(S_ISDIR) && defined(S_IFDIR)
136 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
138 # define S_ISDIR(m) ((m) & S_IFDIR)
142 #if !defined(S_ISREG) && defined(S_IFREG)
144 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
146 # define S_ISREG(m) ((m) & S_IFREG)
150 #if !defined(S_ISFIFO) && defined(S_IFIFO)
152 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
154 # define S_ISFIFO(m) ((m) & S_IFIFO)
158 #if !defined(S_ISLNK) && defined(S_IFLNK)
160 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
162 # define S_ISLNK(m) ((m) & S_IFLNK)
167 # if defined( S_IFSOCK )
169 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
171 # define S_ISSOCK(m) ((m) & S_IFSOCK)
173 # elif defined( S_ISNAM )
174 /* SCO OpenServer 5.0.6a */
175 # define S_ISSOCK S_ISNAM
176 # endif /* !S_IFSOCK && S_ISNAM */
177 #endif /* !S_ISSOCK */
179 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
181 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
182 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
184 # define S_ISMPB(m) ((m) & S_IFMPB)
185 # define S_ISMPC(m) ((m) & S_IFMPC)
189 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
191 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
193 # define S_ISNWK(m) ((m) & S_IFNWK)
197 #ifdef NEED_DECOY_PERMISSIONS /* OS/2, really */
199 #define S_IRUSR S_IREAD
200 #define S_IWUSR S_IWRITE
201 #define S_IXUSR S_IEXEC
202 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
203 #define S_IRGRP S_IREAD
204 #define S_IWGRP S_IWRITE
205 #define S_IXGRP S_IEXEC
206 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
207 #define S_IROTH S_IREAD
208 #define S_IWOTH S_IWRITE
209 #define S_IXOTH S_IEXEC
210 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
212 #else /* ! NEED_DECOY_PERMISSIONS */
218 /* Read, write, and execute by owner. */
219 #define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
221 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
222 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
223 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
224 /* Read, write, and execute by group. */
225 #define S_IRWXG (S_IRWXU >> 3)
227 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
228 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
229 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
230 /* Read, write, and execute by others. */
231 #define S_IRWXO (S_IRWXG >> 3)
232 #endif /* !def S_IRUSR */
233 #endif /* NEED_DECOY_PERMISSIONS */
236 # define DEVNULL "/dev/null"
247 /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h
248 which doesn't define anything. It would be cleaner to have configure
249 check for struct utimbuf, but for now I'm checking NeXT here (so I don't
250 have to debug the configure check across all the machines). */
251 #if defined (HAVE_UTIME_H) && !defined (NeXT)
254 # if defined (HAVE_SYS_UTIME_H)
255 # include <sys/utime.h>
268 /* errno.h variations:
270 * Not all systems set the same error code on a non-existent-file
271 * error. This tries to ask the question somewhat portably.
272 * On systems that don't have ENOTEXIST, this should behave just like
273 * x == ENOENT. "x" is probably errno, of course.
277 # define existence_error(x) \
278 (((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
280 # define existence_error(x) \
281 (((x) == ENOTEXIST) || ((x) == ENOENT))
285 # define existence_error(x) \
286 ((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
288 # define existence_error(x) ((x) == ENOENT)
293 # define CVS_MALLOC malloc
294 # else /* !HAVE_MALLOC */
295 # define CVS_MALLOC rpl_malloc
296 #endif /* HAVE_MALLOC */
298 # define CVS_REALLOC realloc
299 #else /* !HAVE_REALLOC */
300 # define CVS_REALLOC rpl_realloc
301 #endif /* HAVE_REALLOC */
303 #ifndef HAVE_STDLIB_H
311 /* check for POSIX signals */
312 #if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
313 # define POSIX_SIGNALS
316 /* MINIX 1.6 doesn't properly support sigaction */
318 # undef POSIX_SIGNALS
321 /* If !POSIX, try for BSD.. Reason: 4.4BSD implements these as wrappers */
322 #if !defined(POSIX_SIGNALS)
323 # if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
328 /* Under OS/2, this must be included _after_ stdio.h; that's why we do
330 #ifdef USE_OWN_TCPIP_H
337 # include <sys/file.h>
355 # define NAMLEN(dirent) strlen((dirent)->d_name)
357 # define dirent direct
358 # define NAMLEN(dirent) (dirent)->d_namlen
360 # include <sys/ndir.h>
363 # include <sys/dir.h>
370 /* Convert B 512-byte blocks to kilobytes if K is nonzero,
371 otherwise return it unchanged. */
372 #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
379 * Some UNIX distributions don't include these in their stat.h Defined here
380 * because "config.h" is always included last.
383 # define S_IWRITE 0000200 /* write permission, owner */
386 # define S_IWGRP 0000020 /* write permission, grougroup */
389 # define S_IWOTH 0000002 /* write permission, other */
392 /* Under non-UNIX operating systems (MS-DOS, WinNT, MacOS), many filesystem
393 calls take only one argument; permission is handled very differently on
394 those systems than in Unix. So we leave such systems a hook on which they
395 can hang their own definitions. */
398 # define CVS_ACCESS access
402 # define CVS_CHDIR chdir
406 # define CVS_CREAT creat
410 # define CVS_FOPEN fopen
414 # define CVS_FDOPEN fdopen
418 # define CVS_MKDIR mkdir
422 # define CVS_OPEN open
426 # define CVS_READDIR readdir
430 # define CVS_CLOSEDIR closedir
434 # define CVS_OPENDIR opendir
438 # define CVS_RENAME rename
442 # define CVS_RMDIR rmdir
446 /* Use the function from lib/stat.c when the system version is broken.
448 # ifdef HAVE_STAT_EMPTY_STRING_BUG
449 # define CVS_STAT rpl_stat
450 # else /* !HAVE_STAT_EMPTY_STRING_BUG */
451 # define CVS_STAT stat
452 # endif /* HAVE_STAT_EMPTY_STRING_BUG */
455 /* Open question: should CVS_STAT be lstat by default? We need
456 to use lstat in order to handle symbolic links correctly with
457 the PreservePermissions option. -twp */
459 /* Use the function from lib/lstat.c when the system version is broken.
461 # if defined( HAVE_STAT_EMPTY_STRING_BUG ) || !defined( LSTAT_FOLLOWS_SLASHED_SYMLINK )
462 # define CVS_LSTAT rpl_lstat
463 # else /* !defined(HAVE_STAT_EMPTY_STRING_BUG )
464 * && defined( LSTAT_FOLLOWS_SLASHED_SYMLINK )
466 # define CVS_LSTAT lstat
467 # endif /* defined(HAVE_STAT_EMPTY_STRING_BUG )
468 * || !defined( LSTAT_FOLLOWS_SLASHED_SYMLINK )
473 # define CVS_UNLINK unlink
476 /* Wildcard matcher. Should be case-insensitive if the system is. */
478 # define CVS_FNMATCH fnmatch
482 off_t ftello (FILE *);
483 int fseeko (FILE *, off_t, int);
484 #endif /* HAVE_FSEEKO */
488 * According to GNU conventions, we should avoid referencing any macro
489 * containing "WIN" as a reference to Microsoft Windows, as we would like to
490 * avoid any implication that we consider Microsoft Windows any sort of "win".
492 * FIXME: As of 2003-06-09, folks on the GNULIB project were discussing
493 * defining a configure macro to define WOE32 appropriately. If they ever do
494 * write such a beast, we should use it, though in most cases it would be
495 * preferable to avoid referencing any OS or compiler anyhow, per Autoconf
496 * convention, and reference only tested features of the system.
503 #ifdef FILENAMES_CASE_INSENSITIVE
505 # if defined (__CYGWIN32__) || defined (WOE32)
506 /* Under Windows, filenames are case-insensitive, and both / and \
507 are path component separators. */
508 # define FOLD_FN_CHAR(c) (WNT_filename_classes[(unsigned char) (c)])
509 extern unsigned char WNT_filename_classes[];
510 # else /* !__CYGWIN32__ && !WOE32 */
511 /* As far as I know, only Macintosh OS X & VMS make it here, but any
512 * platform defining FILENAMES_CASE_INSENSITIVE which isn't WOE32 or
513 * piggy-backing the same could, in theory. Since the OS X fold just folds
514 * A-Z into a-z, I'm just allowing it to be used for any case insensitive
515 * system which we aren't yet making other specific folds or exceptions for.
516 * WOE32 needs its own class since \ and C:\ style absolute paths also need
517 * to be accounted for.
519 # define FOLD_FN_CHAR(c) (OSX_filename_classes[(unsigned char) (c)])
520 extern unsigned char OSX_filename_classes[];
521 # endif /* __CYGWIN32__ || WOE32 */
523 /* The following need to be declared for all case insensitive filesystems.
524 * When not FOLD_FN_CHAR is not #defined, a default definition for these
525 * functions is provided later in this header file. */
527 /* Like strcmp, but with the appropriate tweaks for file names. */
528 extern int fncmp (const char *n1, const char *n2);
530 /* Fold characters in FILENAME to their canonical forms. */
531 extern void fnfold (char *FILENAME);
533 #endif /* FILENAMES_CASE_INSENSITIVE */
537 /* Some file systems are case-insensitive. If FOLD_FN_CHAR is
538 #defined, it maps the character C onto its "canonical" form. In a
539 case-insensitive system, it would map all alphanumeric characters
540 to lower case. Under Windows NT, / and \ are both path component
541 separators, so FOLD_FN_CHAR would map them both to /. */
543 # define FOLD_FN_CHAR(c) (c)
544 # define fnfold(filename) (filename)
545 # define fncmp strcmp
548 /* Different file systems can have different naming patterns which designate
549 * a path as absolute.
552 # define ISABSOLUTE(s) ISSLASH(s[FILE_SYSTEM_PREFIX_LEN(s)])
556 /* On some systems, we have to be careful about writing/reading files
557 in text or binary mode (so in text mode the system can handle CRLF
558 vs. LF, VMS text file conventions, &c). We decide to just always
559 be careful. That way we don't have to worry about whether text and
560 binary differ on this system. We just have to worry about whether
561 the system has O_BINARY and "rb". The latter is easy; all ANSI C
562 libraries have it, SunOS4 has it, and CVS has used it unguarded
563 some places for a while now without complaints (e.g. "rb" in
564 server.c (server_updated), since CVS 1.8). The former is just an
567 #define FOPEN_BINARY_READ ("rb")
568 #define FOPEN_BINARY_WRITE ("wb")
569 #define FOPEN_BINARY_READWRITE ("r+b")
572 #define OPEN_BINARY (O_BINARY)
574 #define OPEN_BINARY (0)