xref: /openbsd-src/gnu/usr.bin/cvs/lib/system.h (revision 43c1707e6f6829177cb1974ee6615ce6c1307689)
11e72d8d2Sderaadt /* system-dependent definitions for CVS.
21e72d8d2Sderaadt    Copyright (C) 1989-1992 Free Software Foundation, Inc.
31e72d8d2Sderaadt 
41e72d8d2Sderaadt    This program is free software; you can redistribute it and/or modify
51e72d8d2Sderaadt    it under the terms of the GNU General Public License as published by
61e72d8d2Sderaadt    the Free Software Foundation; either version 2, or (at your option)
71e72d8d2Sderaadt    any later version.
81e72d8d2Sderaadt 
91e72d8d2Sderaadt    This program is distributed in the hope that it will be useful,
101e72d8d2Sderaadt    but WITHOUT ANY WARRANTY; without even the implied warranty of
111e72d8d2Sderaadt    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12461cc63eStholo    GNU General Public License for more details.  */
131e72d8d2Sderaadt 
141e72d8d2Sderaadt #include <sys/types.h>
151e72d8d2Sderaadt #include <sys/stat.h>
161e72d8d2Sderaadt 
171e72d8d2Sderaadt #ifdef STAT_MACROS_BROKEN
181e72d8d2Sderaadt #undef S_ISBLK
191e72d8d2Sderaadt #undef S_ISCHR
201e72d8d2Sderaadt #undef S_ISDIR
211e72d8d2Sderaadt #undef S_ISREG
221e72d8d2Sderaadt #undef S_ISFIFO
231e72d8d2Sderaadt #undef S_ISLNK
241e72d8d2Sderaadt #undef S_ISSOCK
251e72d8d2Sderaadt #undef S_ISMPB
261e72d8d2Sderaadt #undef S_ISMPC
271e72d8d2Sderaadt #undef S_ISNWK
281e72d8d2Sderaadt #endif
291e72d8d2Sderaadt 
302286d8edStholo /* Not all systems have S_IFMT, but we want to use it if we have it.
312286d8edStholo    The S_IFMT code below looks right (it masks and compares).  The
322286d8edStholo    non-S_IFMT code looks bogus (are there really systems on which
332286d8edStholo    S_IFBLK, S_IFLNK, &c, each have their own bit?  I suspect it was
342286d8edStholo    written for OS/2 using the IBM C/C++ Tools 2.01 compiler).
352286d8edStholo 
362286d8edStholo    Of course POSIX systems will have S_IS*, so maybe the issue is
372286d8edStholo    semi-moot.  */
3813571821Stholo 
391e72d8d2Sderaadt #if !defined(S_ISBLK) && defined(S_IFBLK)
4013571821Stholo # if defined(S_IFMT)
411e72d8d2Sderaadt # define	S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
4213571821Stholo # else
4313571821Stholo # define S_ISBLK(m) ((m) & S_IFBLK)
441e72d8d2Sderaadt # endif
4513571821Stholo #endif
4613571821Stholo 
471e72d8d2Sderaadt #if !defined(S_ISCHR) && defined(S_IFCHR)
4813571821Stholo # if defined(S_IFMT)
491e72d8d2Sderaadt # define	S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
5013571821Stholo # else
5113571821Stholo # define S_ISCHR(m) ((m) & S_IFCHR)
521e72d8d2Sderaadt # endif
5313571821Stholo #endif
5413571821Stholo 
551e72d8d2Sderaadt #if !defined(S_ISDIR) && defined(S_IFDIR)
5613571821Stholo # if defined(S_IFMT)
571e72d8d2Sderaadt # define	S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
5813571821Stholo # else
5913571821Stholo # define S_ISDIR(m) ((m) & S_IFDIR)
601e72d8d2Sderaadt # endif
6113571821Stholo #endif
6213571821Stholo 
631e72d8d2Sderaadt #if !defined(S_ISREG) && defined(S_IFREG)
6413571821Stholo # if defined(S_IFMT)
651e72d8d2Sderaadt # define	S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
6613571821Stholo # else
6713571821Stholo # define S_ISREG(m) ((m) & S_IFREG)
681e72d8d2Sderaadt # endif
6913571821Stholo #endif
7013571821Stholo 
711e72d8d2Sderaadt #if !defined(S_ISFIFO) && defined(S_IFIFO)
7213571821Stholo # if defined(S_IFMT)
731e72d8d2Sderaadt # define	S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
7413571821Stholo # else
7513571821Stholo # define S_ISFIFO(m) ((m) & S_IFIFO)
761e72d8d2Sderaadt # endif
7713571821Stholo #endif
7813571821Stholo 
791e72d8d2Sderaadt #if !defined(S_ISLNK) && defined(S_IFLNK)
8013571821Stholo # if defined(S_IFMT)
811e72d8d2Sderaadt # define	S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
8213571821Stholo # else
8313571821Stholo # define S_ISLNK(m) ((m) & S_IFLNK)
841e72d8d2Sderaadt # endif
8513571821Stholo #endif
8613571821Stholo 
871e72d8d2Sderaadt #if !defined(S_ISSOCK) && defined(S_IFSOCK)
8813571821Stholo # if defined(S_IFMT)
891e72d8d2Sderaadt # define	S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
9013571821Stholo # else
9113571821Stholo # define S_ISSOCK(m) ((m) & S_IFSOCK)
921e72d8d2Sderaadt # endif
9313571821Stholo #endif
9413571821Stholo 
951e72d8d2Sderaadt #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
9613571821Stholo # if defined(S_IFMT)
971e72d8d2Sderaadt # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
981e72d8d2Sderaadt # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
9913571821Stholo # else
10013571821Stholo # define S_ISMPB(m) ((m) & S_IFMPB)
10113571821Stholo # define S_ISMPC(m) ((m) & S_IFMPC)
1021e72d8d2Sderaadt # endif
10313571821Stholo #endif
10413571821Stholo 
1051e72d8d2Sderaadt #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
10613571821Stholo # if defined(S_IFMT)
1071e72d8d2Sderaadt # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
10813571821Stholo # else
10913571821Stholo # define S_ISNWK(m) ((m) & S_IFNWK)
1101e72d8d2Sderaadt # endif
11113571821Stholo #endif
11213571821Stholo 
11313571821Stholo #ifdef NEED_DECOY_PERMISSIONS        /* OS/2, really */
11413571821Stholo 
11513571821Stholo #define	S_IRUSR S_IREAD
11613571821Stholo #define	S_IWUSR S_IWRITE
11713571821Stholo #define	S_IXUSR S_IEXEC
11813571821Stholo #define	S_IRWXU	(S_IRUSR | S_IWUSR | S_IXUSR)
11913571821Stholo #define	S_IRGRP S_IREAD
12013571821Stholo #define	S_IWGRP S_IWRITE
12113571821Stholo #define	S_IXGRP S_IEXEC
12213571821Stholo #define	S_IRWXG	(S_IRGRP | S_IWGRP | S_IXGRP)
12313571821Stholo #define	S_IROTH S_IREAD
12413571821Stholo #define	S_IWOTH S_IWRITE
12513571821Stholo #define	S_IXOTH S_IEXEC
12613571821Stholo #define	S_IRWXO	(S_IROTH | S_IWOTH | S_IXOTH)
12713571821Stholo 
12813571821Stholo #else /* ! NEED_DECOY_PERMISSIONS */
12913571821Stholo 
1301e72d8d2Sderaadt #ifndef S_IRUSR
1311e72d8d2Sderaadt #define	S_IRUSR 0400
1321e72d8d2Sderaadt #define	S_IWUSR 0200
1331e72d8d2Sderaadt #define	S_IXUSR 0100
1341e72d8d2Sderaadt /* Read, write, and execute by owner.  */
1351e72d8d2Sderaadt #define	S_IRWXU	(S_IRUSR|S_IWUSR|S_IXUSR)
1361e72d8d2Sderaadt 
1371e72d8d2Sderaadt #define	S_IRGRP	(S_IRUSR >> 3)	/* Read by group.  */
1381e72d8d2Sderaadt #define	S_IWGRP	(S_IWUSR >> 3)	/* Write by group.  */
1391e72d8d2Sderaadt #define	S_IXGRP	(S_IXUSR >> 3)	/* Execute by group.  */
1401e72d8d2Sderaadt /* Read, write, and execute by group.  */
1411e72d8d2Sderaadt #define	S_IRWXG	(S_IRWXU >> 3)
1421e72d8d2Sderaadt 
1431e72d8d2Sderaadt #define	S_IROTH	(S_IRGRP >> 3)	/* Read by others.  */
1441e72d8d2Sderaadt #define	S_IWOTH	(S_IWGRP >> 3)	/* Write by others.  */
1451e72d8d2Sderaadt #define	S_IXOTH	(S_IXGRP >> 3)	/* Execute by others.  */
1461e72d8d2Sderaadt /* Read, write, and execute by others.  */
1471e72d8d2Sderaadt #define	S_IRWXO	(S_IRWXG >> 3)
14813571821Stholo #endif /* !def S_IRUSR */
14913571821Stholo #endif /* NEED_DECOY_PERMISSIONS */
1501e72d8d2Sderaadt 
1511e72d8d2Sderaadt #if defined(POSIX) || defined(HAVE_UNISTD_H)
1521e72d8d2Sderaadt #include <unistd.h>
1531e72d8d2Sderaadt #include <limits.h>
1541e72d8d2Sderaadt #else
1551e72d8d2Sderaadt off_t lseek ();
1562286d8edStholo char *getcwd ();
1571e72d8d2Sderaadt #endif
1581e72d8d2Sderaadt 
159*43c1707eStholo #include "xtime.h"
1601e72d8d2Sderaadt 
1611e72d8d2Sderaadt #ifdef HAVE_IO_H
1621e72d8d2Sderaadt #include <io.h>
1631e72d8d2Sderaadt #endif
1641e72d8d2Sderaadt 
1651e72d8d2Sderaadt #ifdef HAVE_DIRECT_H
1661e72d8d2Sderaadt #include <direct.h>
1671e72d8d2Sderaadt #endif
1681e72d8d2Sderaadt 
1691e72d8d2Sderaadt 
1701e72d8d2Sderaadt 
1711e72d8d2Sderaadt /*
1721e72d8d2Sderaadt **  MAXPATHLEN and PATH_MAX
1731e72d8d2Sderaadt **
1741e72d8d2Sderaadt **     On most systems MAXPATHLEN is defined in sys/param.h to be 1024. Of
1751e72d8d2Sderaadt **     those that this is not true, again most define PATH_MAX in limits.h
1761e72d8d2Sderaadt **     or sys/limits.h which usually gets included by limits.h. On the few
1771e72d8d2Sderaadt **     remaining systems that neither statement is true, _POSIX_PATH_MAX
1781e72d8d2Sderaadt **     is defined.
1791e72d8d2Sderaadt **
1801e72d8d2Sderaadt **     So:
1811e72d8d2Sderaadt **         1. If PATH_MAX is defined just use it.
1821e72d8d2Sderaadt **         2. If MAXPATHLEN is defined but not PATH_MAX, then define
1831e72d8d2Sderaadt **            PATH_MAX in terms of MAXPATHLEN.
1841e72d8d2Sderaadt **         3. If neither is defined, include limits.h and check for
1851e72d8d2Sderaadt **            PATH_MAX again.
1861e72d8d2Sderaadt **         3.1 If we now have PATHSIZE, define PATH_MAX in terms of that.
1871e72d8d2Sderaadt **             and ignore the rest.  Since _POSIX_PATH_MAX (checked for
1881e72d8d2Sderaadt **             next) is the *most* restrictive (smallest) value, if we
1891e72d8d2Sderaadt **             trust _POSIX_PATH_MAX, several of our buffers are too small.
1901e72d8d2Sderaadt **         4. If PATH_MAX is still not defined but _POSIX_PATH_MAX is,
1911e72d8d2Sderaadt **            then define PATH_MAX in terms of _POSIX_PATH_MAX.
1921e72d8d2Sderaadt **         5. And if even _POSIX_PATH_MAX doesn't exist just put in
1931e72d8d2Sderaadt **            a reasonable value.
1941e72d8d2Sderaadt **         *. All in all, this is an excellent argument for using pathconf()
1951e72d8d2Sderaadt **            when at all possible.  Or better yet, dynamically allocate
1961e72d8d2Sderaadt **            our buffers and use getcwd() not getwd().
1971e72d8d2Sderaadt **
1981e72d8d2Sderaadt **     This works on:
1991e72d8d2Sderaadt **         Sun Sparc 10        SunOS 4.1.3  &  Solaris 1.2
2001e72d8d2Sderaadt **         HP 9000/700         HP/UX 8.07   &  HP/UX 9.01
2011e72d8d2Sderaadt **         Tektronix XD88/10   UTekV 3.2e
2021e72d8d2Sderaadt **         IBM RS6000          AIX 3.2
2031e72d8d2Sderaadt **         Dec Alpha           OSF 1 ????
2041e72d8d2Sderaadt **         Intel 386           BSDI BSD/386
2051e72d8d2Sderaadt **         Intel 386           SCO OpenServer Release 5
2061e72d8d2Sderaadt **         Apollo              Domain 10.4
2071e72d8d2Sderaadt **         NEC                 SVR4
2081e72d8d2Sderaadt */
2091e72d8d2Sderaadt 
2101e72d8d2Sderaadt /* On MOST systems this will get you MAXPATHLEN.
2111e72d8d2Sderaadt    Windows NT doesn't have this file, tho.  */
2121e72d8d2Sderaadt #ifdef HAVE_SYS_PARAM_H
2131e72d8d2Sderaadt #include <sys/param.h>
2141e72d8d2Sderaadt #endif
2151e72d8d2Sderaadt 
2161e72d8d2Sderaadt #ifndef PATH_MAX
2171e72d8d2Sderaadt #  ifdef MAXPATHLEN
2181e72d8d2Sderaadt #    define PATH_MAX                 MAXPATHLEN
2191e72d8d2Sderaadt #  else
2201e72d8d2Sderaadt #    include <limits.h>
2211e72d8d2Sderaadt #    ifndef PATH_MAX
2221e72d8d2Sderaadt #      ifdef PATHSIZE
2231e72d8d2Sderaadt #         define PATH_MAX               PATHSIZE
2241e72d8d2Sderaadt #      else /* no PATHSIZE */
2251e72d8d2Sderaadt #        ifdef _POSIX_PATH_MAX
2261e72d8d2Sderaadt #          define PATH_MAX             _POSIX_PATH_MAX
2271e72d8d2Sderaadt #        else
2281e72d8d2Sderaadt #          define PATH_MAX             1024
2291e72d8d2Sderaadt #        endif  /* no _POSIX_PATH_MAX */
2301e72d8d2Sderaadt #      endif  /* no PATHSIZE */
2311e72d8d2Sderaadt #    endif /* no PATH_MAX   */
2321e72d8d2Sderaadt #  endif  /* MAXPATHLEN */
2331e72d8d2Sderaadt #endif  /* PATH_MAX   */
2341e72d8d2Sderaadt 
2351e72d8d2Sderaadt 
2361e72d8d2Sderaadt /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h
2371e72d8d2Sderaadt    which doesn't define anything.  It would be cleaner to have configure
2381e72d8d2Sderaadt    check for struct utimbuf, but for now I'm checking NeXT here (so I don't
2391e72d8d2Sderaadt    have to debug the configure check across all the machines).  */
2401e72d8d2Sderaadt #if defined (HAVE_UTIME_H) && !defined (NeXT)
2411e72d8d2Sderaadt #  include <utime.h>
24250bf276cStholo #else
24350bf276cStholo #  if defined (HAVE_SYS_UTIME_H)
24413571821Stholo #    include <sys/utime.h>
2451e72d8d2Sderaadt #  else
2461e72d8d2Sderaadt #    ifndef ALTOS
2471e72d8d2Sderaadt struct utimbuf
2481e72d8d2Sderaadt {
2491e72d8d2Sderaadt   long actime;
2501e72d8d2Sderaadt   long modtime;
2511e72d8d2Sderaadt };
2521e72d8d2Sderaadt #    endif
2531e72d8d2Sderaadt int utime ();
2541e72d8d2Sderaadt #  endif
25550bf276cStholo #endif
2561e72d8d2Sderaadt 
2571e72d8d2Sderaadt #include <string.h>
2581e72d8d2Sderaadt 
25950bf276cStholo #ifndef ERRNO_H_MISSING
2601e72d8d2Sderaadt #include <errno.h>
26150bf276cStholo #endif
26213571821Stholo 
26313571821Stholo /* Not all systems set the same error code on a non-existent-file
26413571821Stholo    error.  This tries to ask the question somewhat portably.
26513571821Stholo    On systems that don't have ENOTEXIST, this should behave just like
26613571821Stholo    x == ENOENT.  "x" is probably errno, of course. */
26713571821Stholo 
26813571821Stholo #ifdef ENOTEXIST
26913571821Stholo #  ifdef EOS2ERR
27013571821Stholo #    define existence_error(x) \
27113571821Stholo      (((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
27213571821Stholo #  else
27313571821Stholo #    define existence_error(x) \
27413571821Stholo      (((x) == ENOTEXIST) || ((x) == ENOENT))
27513571821Stholo #  endif
27613571821Stholo #else
277c2c61682Stholo #  ifdef EVMSERR
278c2c61682Stholo #     define existence_error(x) \
279c2c61682Stholo ((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
280c2c61682Stholo #  else
28113571821Stholo #    define existence_error(x) ((x) == ENOENT)
28213571821Stholo #  endif
283c2c61682Stholo #endif
28413571821Stholo 
28513571821Stholo 
2861e72d8d2Sderaadt #ifdef STDC_HEADERS
2871e72d8d2Sderaadt #include <stdlib.h>
2881e72d8d2Sderaadt #else
2891e72d8d2Sderaadt char *getenv ();
2901e72d8d2Sderaadt char *malloc ();
2911e72d8d2Sderaadt char *realloc ();
2921e72d8d2Sderaadt char *calloc ();
2931e72d8d2Sderaadt extern int errno;
2941e72d8d2Sderaadt #endif
2951e72d8d2Sderaadt 
296c2c61682Stholo /* SunOS4 apparently does not define this in stdlib.h.  */
297c2c61682Stholo #ifndef EXIT_FAILURE
298c2c61682Stholo #define EXIT_FAILURE 1
299c2c61682Stholo #endif
300c2c61682Stholo 
30113571821Stholo /* check for POSIX signals */
30213571821Stholo #if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
30313571821Stholo # define POSIX_SIGNALS
30413571821Stholo #endif
30513571821Stholo 
30613571821Stholo /* MINIX 1.6 doesn't properly support sigaction */
30713571821Stholo #if defined(_MINIX)
30813571821Stholo # undef POSIX_SIGNALS
30913571821Stholo #endif
31013571821Stholo 
31113571821Stholo /* If !POSIX, try for BSD.. Reason: 4.4BSD implements these as wrappers */
31213571821Stholo #if !defined(POSIX_SIGNALS)
31313571821Stholo # if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
31413571821Stholo #  define BSD_SIGNALS
31513571821Stholo # endif
31613571821Stholo #endif
31713571821Stholo 
31813571821Stholo /* Under OS/2, this must be included _after_ stdio.h; that's why we do
31913571821Stholo    it here. */
32013571821Stholo #ifdef USE_OWN_TCPIP_H
32113571821Stholo #include "tcpip.h"
32213571821Stholo #endif
32313571821Stholo 
3241e72d8d2Sderaadt #ifdef HAVE_FCNTL_H
3251e72d8d2Sderaadt #include <fcntl.h>
3261e72d8d2Sderaadt #else
3271e72d8d2Sderaadt #include <sys/file.h>
3281e72d8d2Sderaadt #endif
3291e72d8d2Sderaadt 
3301e72d8d2Sderaadt #ifndef SEEK_SET
3311e72d8d2Sderaadt #define SEEK_SET 0
3321e72d8d2Sderaadt #define SEEK_CUR 1
3331e72d8d2Sderaadt #define SEEK_END 2
3341e72d8d2Sderaadt #endif
3351e72d8d2Sderaadt 
3361e72d8d2Sderaadt #ifndef F_OK
3371e72d8d2Sderaadt #define F_OK 0
3381e72d8d2Sderaadt #define X_OK 1
3391e72d8d2Sderaadt #define W_OK 2
3401e72d8d2Sderaadt #define R_OK 4
3411e72d8d2Sderaadt #endif
3421e72d8d2Sderaadt 
3431e72d8d2Sderaadt #if HAVE_DIRENT_H
3441e72d8d2Sderaadt # include <dirent.h>
3451e72d8d2Sderaadt # define NAMLEN(dirent) strlen((dirent)->d_name)
3461e72d8d2Sderaadt #else
3471e72d8d2Sderaadt # define dirent direct
3481e72d8d2Sderaadt # define NAMLEN(dirent) (dirent)->d_namlen
3491e72d8d2Sderaadt # if HAVE_SYS_NDIR_H
3501e72d8d2Sderaadt #  include <sys/ndir.h>
3511e72d8d2Sderaadt # endif
3521e72d8d2Sderaadt # if HAVE_SYS_DIR_H
3531e72d8d2Sderaadt #  include <sys/dir.h>
3541e72d8d2Sderaadt # endif
3551e72d8d2Sderaadt # if HAVE_NDIR_H
3561e72d8d2Sderaadt #  include <ndir.h>
3571e72d8d2Sderaadt # endif
3581e72d8d2Sderaadt #endif
3591e72d8d2Sderaadt 
3601e72d8d2Sderaadt /* Convert B 512-byte blocks to kilobytes if K is nonzero,
3611e72d8d2Sderaadt    otherwise return it unchanged. */
3621e72d8d2Sderaadt #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
3631e72d8d2Sderaadt 
3641e72d8d2Sderaadt #ifndef S_ISLNK
3651e72d8d2Sderaadt #define lstat stat
3661e72d8d2Sderaadt #endif
3671e72d8d2Sderaadt 
3681e72d8d2Sderaadt /*
3691e72d8d2Sderaadt  * Some UNIX distributions don't include these in their stat.h Defined here
3701e72d8d2Sderaadt  * because "config.h" is always included last.
3711e72d8d2Sderaadt  */
3721e72d8d2Sderaadt #ifndef S_IWRITE
3731e72d8d2Sderaadt #define	S_IWRITE	0000200		/* write permission, owner */
3741e72d8d2Sderaadt #endif
3751e72d8d2Sderaadt #ifndef S_IWGRP
3761e72d8d2Sderaadt #define	S_IWGRP		0000020		/* write permission, grougroup */
3771e72d8d2Sderaadt #endif
3781e72d8d2Sderaadt #ifndef S_IWOTH
3791e72d8d2Sderaadt #define	S_IWOTH		0000002		/* write permission, other */
3801e72d8d2Sderaadt #endif
3811e72d8d2Sderaadt 
38250bf276cStholo /* Under non-UNIX operating systems (MS-DOS, WinNT, MacOS), many filesystem
38350bf276cStholo    calls take  only one argument; permission is handled very differently on
38450bf276cStholo    those systems than in Unix.  So we leave such systems a hook on which they
38550bf276cStholo    can hang their own definitions.  */
38650bf276cStholo 
38750bf276cStholo #ifndef CVS_ACCESS
38850bf276cStholo #define CVS_ACCESS access
38950bf276cStholo #endif
39050bf276cStholo 
39150bf276cStholo #ifndef CVS_CHDIR
39250bf276cStholo #define CVS_CHDIR chdir
39350bf276cStholo #endif
39450bf276cStholo 
39550bf276cStholo #ifndef CVS_CREAT
39650bf276cStholo #define CVS_CREAT creat
39750bf276cStholo #endif
39850bf276cStholo 
39950bf276cStholo #ifndef CVS_FOPEN
40050bf276cStholo #define CVS_FOPEN fopen
40150bf276cStholo #endif
40250bf276cStholo 
403*43c1707eStholo #ifndef CVS_FDOPEN
404*43c1707eStholo #define CVS_FDOPEN fdopen
405*43c1707eStholo #endif
406*43c1707eStholo 
4071e72d8d2Sderaadt #ifndef CVS_MKDIR
4081e72d8d2Sderaadt #define CVS_MKDIR mkdir
4091e72d8d2Sderaadt #endif
4101e72d8d2Sderaadt 
41150bf276cStholo #ifndef CVS_OPEN
41250bf276cStholo #define CVS_OPEN open
41350bf276cStholo #endif
41450bf276cStholo 
415*43c1707eStholo #ifndef CVS_READDIR
416*43c1707eStholo #define CVS_READDIR readdir
417*43c1707eStholo #endif
418*43c1707eStholo 
419*43c1707eStholo #ifndef CVS_CLOSEDIR
420*43c1707eStholo #define CVS_CLOSEDIR closedir
421*43c1707eStholo #endif
422*43c1707eStholo 
42350bf276cStholo #ifndef CVS_OPENDIR
42450bf276cStholo #define CVS_OPENDIR opendir
42550bf276cStholo #endif
42650bf276cStholo 
42750bf276cStholo #ifndef CVS_RENAME
42850bf276cStholo #define CVS_RENAME rename
42950bf276cStholo #endif
43050bf276cStholo 
43150bf276cStholo #ifndef CVS_RMDIR
43250bf276cStholo #define CVS_RMDIR rmdir
43350bf276cStholo #endif
43450bf276cStholo 
43550bf276cStholo #ifndef CVS_STAT
43650bf276cStholo #define CVS_STAT stat
43750bf276cStholo #endif
43850bf276cStholo 
4395e617892Stholo /* Open question: should CVS_STAT be lstat by default?  We need
4405e617892Stholo    to use lstat in order to handle symbolic links correctly with
4415e617892Stholo    the PreservePermissions option. -twp */
4425e617892Stholo #ifndef CVS_LSTAT
4435e617892Stholo #define CVS_LSTAT lstat
4445e617892Stholo #endif
4455e617892Stholo 
44650bf276cStholo #ifndef CVS_UNLINK
44750bf276cStholo #define CVS_UNLINK unlink
44850bf276cStholo #endif
44950bf276cStholo 
4502770ece5Stholo /* Wildcard matcher.  Should be case-insensitive if the system is.  */
4512770ece5Stholo #ifndef CVS_FNMATCH
4522770ece5Stholo #define CVS_FNMATCH fnmatch
4532770ece5Stholo #endif
4542770ece5Stholo 
4552286d8edStholo #if defined (__CYGWIN32__) || defined (WIN32)
4562286d8edStholo 
4572286d8edStholo /* Under Windows NT, filenames are case-insensitive, and both / and \
4582286d8edStholo    are path component separators.  */
4592286d8edStholo 
4602286d8edStholo #define FOLD_FN_CHAR(c) (WNT_filename_classes[(unsigned char) (c)])
4612286d8edStholo extern unsigned char WNT_filename_classes[];
4622286d8edStholo #define FILENAMES_CASE_INSENSITIVE 1
4632286d8edStholo 
4642286d8edStholo /* Is the character C a path name separator?  Under
4652286d8edStholo    Windows NT, you can use either / or \.  */
4662286d8edStholo #define ISDIRSEP(c) (FOLD_FN_CHAR(c) == '/')
4672286d8edStholo 
4682286d8edStholo /* Like strcmp, but with the appropriate tweaks for file names.
4692286d8edStholo    Under Windows NT, filenames are case-insensitive but case-preserving,
4702286d8edStholo    and both \ and / are path element separators.  */
4712286d8edStholo extern int fncmp (const char *n1, const char *n2);
4722286d8edStholo 
4732286d8edStholo /* Fold characters in FILENAME to their canonical forms.
4742286d8edStholo    If FOLD_FN_CHAR is not #defined, the system provides a default
4752286d8edStholo    definition for this.  */
4762286d8edStholo extern void fnfold (char *FILENAME);
4772286d8edStholo 
4782286d8edStholo #endif /* defined (__CYGWIN32__) || defined (WIN32) */
4792286d8edStholo 
4801e72d8d2Sderaadt /* Some file systems are case-insensitive.  If FOLD_FN_CHAR is
4811e72d8d2Sderaadt    #defined, it maps the character C onto its "canonical" form.  In a
4821e72d8d2Sderaadt    case-insensitive system, it would map all alphanumeric characters
4831e72d8d2Sderaadt    to lower case.  Under Windows NT, / and \ are both path component
4841e72d8d2Sderaadt    separators, so FOLD_FN_CHAR would map them both to /.  */
4851e72d8d2Sderaadt #ifndef FOLD_FN_CHAR
4861e72d8d2Sderaadt #define FOLD_FN_CHAR(c) (c)
4871e72d8d2Sderaadt #define fnfold(filename) (filename)
4881e72d8d2Sderaadt #define fncmp strcmp
4891e72d8d2Sderaadt #endif
4901e72d8d2Sderaadt 
4911e72d8d2Sderaadt /* Different file systems have different path component separators.
4921e72d8d2Sderaadt    For the VMS port we might need to abstract further back than this.  */
4931e72d8d2Sderaadt #ifndef ISDIRSEP
4941e72d8d2Sderaadt #define ISDIRSEP(c) ((c) == '/')
4951e72d8d2Sderaadt #endif
4961e72d8d2Sderaadt 
4971e72d8d2Sderaadt 
4982286d8edStholo /* On some systems, we have to be careful about writing/reading files
4992286d8edStholo    in text or binary mode (so in text mode the system can handle CRLF
5002286d8edStholo    vs. LF, VMS text file conventions, &c).  We decide to just always
5012286d8edStholo    be careful.  That way we don't have to worry about whether text and
5022286d8edStholo    binary differ on this system.  We just have to worry about whether
5032286d8edStholo    the system has O_BINARY and "rb".  The latter is easy; all ANSI C
5042286d8edStholo    libraries have it, SunOS4 has it, and CVS has used it unguarded
5052286d8edStholo    some places for a while now without complaints (e.g. "rb" in
5062286d8edStholo    server.c (server_updated), since CVS 1.8).  The former is just an
5072286d8edStholo    #ifdef.  */
5082286d8edStholo 
5091e72d8d2Sderaadt #define FOPEN_BINARY_READ ("rb")
5101e72d8d2Sderaadt #define FOPEN_BINARY_WRITE ("wb")
5112286d8edStholo 
5122286d8edStholo #ifdef O_BINARY
5132286d8edStholo #define OPEN_BINARY (O_BINARY)
5141e72d8d2Sderaadt #else
5151e72d8d2Sderaadt #define OPEN_BINARY (0)
5161e72d8d2Sderaadt #endif
517