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. */
14 #include <sys/types.h>
17 #ifdef STAT_MACROS_BROKEN
30 /* Not all systems have S_IFMT, but we want to use it if we have it.
31 The S_IFMT code below looks right (it masks and compares). The
32 non-S_IFMT code looks bogus (are there really systems on which
33 S_IFBLK, S_IFLNK, &c, each have their own bit? I suspect it was
34 written for OS/2 using the IBM C/C++ Tools 2.01 compiler).
36 Of course POSIX systems will have S_IS*, so maybe the issue is
39 #if !defined(S_ISBLK) && defined(S_IFBLK)
41 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
43 # define S_ISBLK(m) ((m) & S_IFBLK)
47 #if !defined(S_ISCHR) && defined(S_IFCHR)
49 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
51 # define S_ISCHR(m) ((m) & S_IFCHR)
55 #if !defined(S_ISDIR) && defined(S_IFDIR)
57 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
59 # define S_ISDIR(m) ((m) & S_IFDIR)
63 #if !defined(S_ISREG) && defined(S_IFREG)
65 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
67 # define S_ISREG(m) ((m) & S_IFREG)
71 #if !defined(S_ISFIFO) && defined(S_IFIFO)
73 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
75 # define S_ISFIFO(m) ((m) & S_IFIFO)
79 #if !defined(S_ISLNK) && defined(S_IFLNK)
81 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
83 # define S_ISLNK(m) ((m) & S_IFLNK)
88 # if defined( S_IFSOCK )
90 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
92 # define S_ISSOCK(m) ((m) & S_IFSOCK)
94 # elif defined( S_ISNAM )
95 /* SCO OpenServer 5.0.6a */
96 # define S_ISSOCK S_ISNAM
97 # endif /* !S_IFSOCK && S_ISNAM */
98 #endif /* !S_ISSOCK */
100 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
102 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
103 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
105 # define S_ISMPB(m) ((m) & S_IFMPB)
106 # define S_ISMPC(m) ((m) & S_IFMPC)
110 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
112 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
114 # define S_ISNWK(m) ((m) & S_IFNWK)
118 #ifdef NEED_DECOY_PERMISSIONS /* OS/2, really */
120 #define S_IRUSR S_IREAD
121 #define S_IWUSR S_IWRITE
122 #define S_IXUSR S_IEXEC
123 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
124 #define S_IRGRP S_IREAD
125 #define S_IWGRP S_IWRITE
126 #define S_IXGRP S_IEXEC
127 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
128 #define S_IROTH S_IREAD
129 #define S_IWOTH S_IWRITE
130 #define S_IXOTH S_IEXEC
131 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
133 #else /* ! NEED_DECOY_PERMISSIONS */
139 /* Read, write, and execute by owner. */
140 #define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
142 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
143 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
144 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
145 /* Read, write, and execute by group. */
146 #define S_IRWXG (S_IRWXU >> 3)
148 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
149 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
150 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
151 /* Read, write, and execute by others. */
152 #define S_IRWXO (S_IRWXG >> 3)
153 #endif /* !def S_IRUSR */
154 #endif /* NEED_DECOY_PERMISSIONS */
156 #if defined(POSIX) || defined(HAVE_UNISTD_H)
177 ** MAXPATHLEN and PATH_MAX
179 ** On most systems MAXPATHLEN is defined in sys/param.h to be 1024. Of
180 ** those that this is not true, again most define PATH_MAX in limits.h
181 ** or sys/limits.h which usually gets included by limits.h. On the few
182 ** remaining systems that neither statement is true, _POSIX_PATH_MAX
186 ** 1. If PATH_MAX is defined just use it.
187 ** 2. If MAXPATHLEN is defined but not PATH_MAX, then define
188 ** PATH_MAX in terms of MAXPATHLEN.
189 ** 3. If neither is defined, include limits.h and check for
191 ** 3.1 If we now have PATHSIZE, define PATH_MAX in terms of that.
192 ** and ignore the rest. Since _POSIX_PATH_MAX (checked for
193 ** next) is the *most* restrictive (smallest) value, if we
194 ** trust _POSIX_PATH_MAX, several of our buffers are too small.
195 ** 4. If PATH_MAX is still not defined but _POSIX_PATH_MAX is,
196 ** then define PATH_MAX in terms of _POSIX_PATH_MAX.
197 ** 5. And if even _POSIX_PATH_MAX doesn't exist just put in
198 ** a reasonable value.
199 ** *. All in all, this is an excellent argument for using pathconf()
200 ** when at all possible. Or better yet, dynamically allocate
201 ** our buffers and use getcwd() not getwd().
204 ** Sun Sparc 10 SunOS 4.1.3 & Solaris 1.2
205 ** HP 9000/700 HP/UX 8.07 & HP/UX 9.01
206 ** Tektronix XD88/10 UTekV 3.2e
207 ** IBM RS6000 AIX 3.2
208 ** Dec Alpha OSF 1 ????
209 ** Intel 386 BSDI BSD/386
210 ** Intel 386 SCO OpenServer Release 5
211 ** Apollo Domain 10.4
215 /* On MOST systems this will get you MAXPATHLEN.
216 Windows NT doesn't have this file, tho. */
217 #ifdef HAVE_SYS_PARAM_H
218 #include <sys/param.h>
223 # define PATH_MAX MAXPATHLEN
228 # define PATH_MAX PATHSIZE
229 # else /* no PATHSIZE */
230 # ifdef _POSIX_PATH_MAX
231 # define PATH_MAX _POSIX_PATH_MAX
233 # define PATH_MAX 1024
234 # endif /* no _POSIX_PATH_MAX */
235 # endif /* no PATHSIZE */
236 # endif /* no PATH_MAX */
237 # endif /* MAXPATHLEN */
238 #endif /* PATH_MAX */
241 /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h
242 which doesn't define anything. It would be cleaner to have configure
243 check for struct utimbuf, but for now I'm checking NeXT here (so I don't
244 have to debug the configure check across all the machines). */
245 #if defined (HAVE_UTIME_H) && !defined (NeXT)
248 # if defined (HAVE_SYS_UTIME_H)
249 # include <sys/utime.h>
264 #ifndef ERRNO_H_MISSING
268 /* Not all systems set the same error code on a non-existent-file
269 error. This tries to ask the question somewhat portably.
270 On systems that don't have ENOTEXIST, this should behave just like
271 x == ENOENT. "x" is probably errno, of course. */
275 # define existence_error(x) \
276 (((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
278 # define existence_error(x) \
279 (((x) == ENOTEXIST) || ((x) == ENOENT))
283 # define existence_error(x) \
284 ((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
286 # define existence_error(x) ((x) == ENOENT)
301 /* SunOS4 apparently does not define this in stdlib.h. */
303 # define EXIT_FAILURE 1
306 /* check for POSIX signals */
307 #if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
308 # define POSIX_SIGNALS
311 /* MINIX 1.6 doesn't properly support sigaction */
313 # undef POSIX_SIGNALS
316 /* If !POSIX, try for BSD.. Reason: 4.4BSD implements these as wrappers */
317 #if !defined(POSIX_SIGNALS)
318 # if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
323 /* Under OS/2, this must be included _after_ stdio.h; that's why we do
325 #ifdef USE_OWN_TCPIP_H
332 # include <sys/file.h>
350 # define NAMLEN(dirent) strlen((dirent)->d_name)
352 # define dirent direct
353 # define NAMLEN(dirent) (dirent)->d_namlen
355 # include <sys/ndir.h>
358 # include <sys/dir.h>
365 /* Convert B 512-byte blocks to kilobytes if K is nonzero,
366 otherwise return it unchanged. */
367 #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
374 * Some UNIX distributions don't include these in their stat.h Defined here
375 * because "config.h" is always included last.
378 # define S_IWRITE 0000200 /* write permission, owner */
381 # define S_IWGRP 0000020 /* write permission, grougroup */
384 # define S_IWOTH 0000002 /* write permission, other */
387 /* Under non-UNIX operating systems (MS-DOS, WinNT, MacOS), many filesystem
388 calls take only one argument; permission is handled very differently on
389 those systems than in Unix. So we leave such systems a hook on which they
390 can hang their own definitions. */
393 # define CVS_ACCESS access
397 # define CVS_CHDIR chdir
401 # define CVS_CREAT creat
405 # define CVS_FOPEN fopen
409 # define CVS_FDOPEN fdopen
413 # define CVS_MKDIR mkdir
417 # define CVS_OPEN open
421 # define CVS_READDIR readdir
425 # define CVS_CLOSEDIR closedir
429 # define CVS_OPENDIR opendir
433 # define CVS_RENAME rename
437 # define CVS_RMDIR rmdir
441 # define CVS_STAT stat
444 /* Open question: should CVS_STAT be lstat by default? We need
445 to use lstat in order to handle symbolic links correctly with
446 the PreservePermissions option. -twp */
448 # define CVS_LSTAT lstat
452 # define CVS_UNLINK unlink
455 /* Wildcard matcher. Should be case-insensitive if the system is. */
457 # define CVS_FNMATCH fnmatch
462 * According to GNU conventions, we should avoid referencing any macro
463 * containing "WIN" as a reference to Microsoft Windows, as we would like to
464 * avoid any implication that we consider Microsoft Windows any sort of "win".
466 * FIXME: As of 2003-06-09, folks on the GNULIB project were discussing
467 * defining a configure macro to define WOE32 appropriately. If they ever do
468 * write such a beast, we should use it, though in most cases it would be
469 * preferable to avoid referencing any OS or compiler anyhow, per Autoconf
470 * convention, and reference only tested features of the system.
477 /* Under Windows NT, filenames are case-insensitive. */
478 # define FILENAMES_CASE_INSENSITIVE 1
483 #ifdef FILENAMES_CASE_INSENSITIVE
485 # if defined (__CYGWIN32__) || defined (WOE32)
486 /* Under Windows, filenames are case-insensitive, and both / and \
487 are path component separators. */
488 # define FOLD_FN_CHAR(c) (WNT_filename_classes[(unsigned char) (c)])
489 extern unsigned char WNT_filename_classes[];
490 /* Is the character C a path name separator? Under
491 Windows NT, you can use either / or \. */
492 # define ISDIRSEP(c) (FOLD_FN_CHAR(c) == '/')
493 # define ISABSOLUTE(s) (ISDIRSEP(s[0]) || FOLD_FN_CHAR(s[0]) >= 'a' && FOLD_FN_CHAR(s[0]) <= 'z' && s[1] == ':' && ISDIRSEP(s[2]))
494 # else /* !__CYGWIN32__ && !WOE32 */
495 /* As far as I know, only Macintosh OS X & VMS make it here, but any
496 * platform defining FILENAMES_CASE_INSENSITIVE which isn't WOE32 or
497 * piggy-backing the same could, in theory. Since the OS X fold just folds
498 * A-Z into a-z, I'm just allowing it to be used for any case insensitive
499 * system which we aren't yet making other specific folds or exceptions for.
500 * WOE32 needs its own class since \ and C:\ style absolute paths also need
501 * to be accounted for.
503 # if defined(USE_VMS_FILENAMES)
504 # define FOLD_FN_CHAR(c) (VMS_filename_classes[(unsigned char) (c)])
505 extern unsigned char VMS_filename_classes[];
507 # define FOLD_FN_CHAR(c) (OSX_filename_classes[(unsigned char) (c)])
508 extern unsigned char OSX_filename_classes[];
510 # endif /* __CYGWIN32__ || WOE32 */
512 /* The following need to be declared for all case insensitive filesystems.
513 * When not FOLD_FN_CHAR is not #defined, a default definition for these
514 * functions is provided later in this header file. */
516 /* Like strcmp, but with the appropriate tweaks for file names. */
517 extern int fncmp (const char *n1, const char *n2);
519 /* Fold characters in FILENAME to their canonical forms. */
520 extern void fnfold (char *FILENAME);
522 #endif /* FILENAMES_CASE_INSENSITIVE */
526 /* Some file systems are case-insensitive. If FOLD_FN_CHAR is
527 #defined, it maps the character C onto its "canonical" form. In a
528 case-insensitive system, it would map all alphanumeric characters
529 to lower case. Under Windows NT, / and \ are both path component
530 separators, so FOLD_FN_CHAR would map them both to /. */
532 # define FOLD_FN_CHAR(c) (c)
533 # define fnfold(filename) (filename)
534 # define fncmp strcmp
537 /* Different file systems have different path component separators.
538 For the VMS port we might need to abstract further back than this. */
540 # define ISDIRSEP(c) ((c) == '/')
543 /* Different file systems can have different naming patterns which designate
547 # define ISABSOLUTE(s) ISDIRSEP(s[0])
551 /* On some systems, we have to be careful about writing/reading files
552 in text or binary mode (so in text mode the system can handle CRLF
553 vs. LF, VMS text file conventions, &c). We decide to just always
554 be careful. That way we don't have to worry about whether text and
555 binary differ on this system. We just have to worry about whether
556 the system has O_BINARY and "rb". The latter is easy; all ANSI C
557 libraries have it, SunOS4 has it, and CVS has used it unguarded
558 some places for a while now without complaints (e.g. "rb" in
559 server.c (server_updated), since CVS 1.8). The former is just an
562 #define FOPEN_BINARY_READ ("rb")
563 #define FOPEN_BINARY_WRITE ("wb")
564 #define FOPEN_BINARY_READWRITE ("r+b")
567 #define OPEN_BINARY (O_BINARY)
569 #define OPEN_BINARY (0)