xref: /openbsd-src/gnu/usr.bin/cvs/lib/system.h (revision 50bf276cd1c7e20f1eda64a5e63e0fae39e12a95)
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
121e72d8d2Sderaadt    GNU General Public License for more details.
131e72d8d2Sderaadt 
141e72d8d2Sderaadt    You should have received a copy of the GNU General Public License
151e72d8d2Sderaadt    along with this program; if not, write to the Free Software
161e72d8d2Sderaadt    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
171e72d8d2Sderaadt 
181e72d8d2Sderaadt /* $CVSid: @(#)system.h 1.18 94/09/25 $ */
191e72d8d2Sderaadt 
201e72d8d2Sderaadt #include <sys/types.h>
211e72d8d2Sderaadt #include <sys/stat.h>
221e72d8d2Sderaadt 
231e72d8d2Sderaadt #ifdef STAT_MACROS_BROKEN
241e72d8d2Sderaadt #undef S_ISBLK
251e72d8d2Sderaadt #undef S_ISCHR
261e72d8d2Sderaadt #undef S_ISDIR
271e72d8d2Sderaadt #undef S_ISREG
281e72d8d2Sderaadt #undef S_ISFIFO
291e72d8d2Sderaadt #undef S_ISLNK
301e72d8d2Sderaadt #undef S_ISSOCK
311e72d8d2Sderaadt #undef S_ISMPB
321e72d8d2Sderaadt #undef S_ISMPC
331e72d8d2Sderaadt #undef S_ISNWK
341e72d8d2Sderaadt #endif
351e72d8d2Sderaadt 
3613571821Stholo /* Not all systems have S_IFMT, but we probably want to use it if we
3713571821Stholo    do.  See ChangeLog for a more detailed discussion. */
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 
1131e72d8d2Sderaadt #if !defined(HAVE_MKFIFO)
1141e72d8d2Sderaadt #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
1151e72d8d2Sderaadt #endif
1161e72d8d2Sderaadt 
11713571821Stholo #ifdef NEED_DECOY_PERMISSIONS        /* OS/2, really */
11813571821Stholo 
11913571821Stholo #define	S_IRUSR S_IREAD
12013571821Stholo #define	S_IWUSR S_IWRITE
12113571821Stholo #define	S_IXUSR S_IEXEC
12213571821Stholo #define	S_IRWXU	(S_IRUSR | S_IWUSR | S_IXUSR)
12313571821Stholo #define	S_IRGRP S_IREAD
12413571821Stholo #define	S_IWGRP S_IWRITE
12513571821Stholo #define	S_IXGRP S_IEXEC
12613571821Stholo #define	S_IRWXG	(S_IRGRP | S_IWGRP | S_IXGRP)
12713571821Stholo #define	S_IROTH S_IREAD
12813571821Stholo #define	S_IWOTH S_IWRITE
12913571821Stholo #define	S_IXOTH S_IEXEC
13013571821Stholo #define	S_IRWXO	(S_IROTH | S_IWOTH | S_IXOTH)
13113571821Stholo 
13213571821Stholo #else /* ! NEED_DECOY_PERMISSIONS */
13313571821Stholo 
1341e72d8d2Sderaadt #ifndef S_IRUSR
1351e72d8d2Sderaadt #define	S_IRUSR 0400
1361e72d8d2Sderaadt #define	S_IWUSR 0200
1371e72d8d2Sderaadt #define	S_IXUSR 0100
1381e72d8d2Sderaadt /* Read, write, and execute by owner.  */
1391e72d8d2Sderaadt #define	S_IRWXU	(S_IRUSR|S_IWUSR|S_IXUSR)
1401e72d8d2Sderaadt 
1411e72d8d2Sderaadt #define	S_IRGRP	(S_IRUSR >> 3)	/* Read by group.  */
1421e72d8d2Sderaadt #define	S_IWGRP	(S_IWUSR >> 3)	/* Write by group.  */
1431e72d8d2Sderaadt #define	S_IXGRP	(S_IXUSR >> 3)	/* Execute by group.  */
1441e72d8d2Sderaadt /* Read, write, and execute by group.  */
1451e72d8d2Sderaadt #define	S_IRWXG	(S_IRWXU >> 3)
1461e72d8d2Sderaadt 
1471e72d8d2Sderaadt #define	S_IROTH	(S_IRGRP >> 3)	/* Read by others.  */
1481e72d8d2Sderaadt #define	S_IWOTH	(S_IWGRP >> 3)	/* Write by others.  */
1491e72d8d2Sderaadt #define	S_IXOTH	(S_IXGRP >> 3)	/* Execute by others.  */
1501e72d8d2Sderaadt /* Read, write, and execute by others.  */
1511e72d8d2Sderaadt #define	S_IRWXO	(S_IRWXG >> 3)
15213571821Stholo #endif /* !def S_IRUSR */
15313571821Stholo #endif /* NEED_DECOY_PERMISSIONS */
1541e72d8d2Sderaadt 
1551e72d8d2Sderaadt #if defined(POSIX) || defined(HAVE_UNISTD_H)
1561e72d8d2Sderaadt #include <unistd.h>
1571e72d8d2Sderaadt #include <limits.h>
1581e72d8d2Sderaadt #else
1591e72d8d2Sderaadt off_t lseek ();
1601e72d8d2Sderaadt #endif
1611e72d8d2Sderaadt 
1621e72d8d2Sderaadt #if TIME_WITH_SYS_TIME
1631e72d8d2Sderaadt # include <sys/time.h>
1641e72d8d2Sderaadt # include <time.h>
1651e72d8d2Sderaadt #else
1661e72d8d2Sderaadt # if HAVE_SYS_TIME_H
1671e72d8d2Sderaadt #  include <sys/time.h>
1681e72d8d2Sderaadt # else
1691e72d8d2Sderaadt #  include <time.h>
1701e72d8d2Sderaadt # endif
1711e72d8d2Sderaadt #endif
1721e72d8d2Sderaadt 
1731e72d8d2Sderaadt #ifdef HAVE_IO_H
1741e72d8d2Sderaadt #include <io.h>
1751e72d8d2Sderaadt #endif
1761e72d8d2Sderaadt 
1771e72d8d2Sderaadt #ifdef HAVE_DIRECT_H
1781e72d8d2Sderaadt #include <direct.h>
1791e72d8d2Sderaadt #endif
1801e72d8d2Sderaadt 
1811e72d8d2Sderaadt #ifdef timezone
1821e72d8d2Sderaadt #undef timezone /* needed for sgi */
1831e72d8d2Sderaadt #endif
1841e72d8d2Sderaadt 
1851e72d8d2Sderaadt #ifdef HAVE_SYS_TIMEB_H
1861e72d8d2Sderaadt #include <sys/timeb.h>
1871e72d8d2Sderaadt #else
1881e72d8d2Sderaadt struct timeb {
1891e72d8d2Sderaadt     time_t		time;		/* Seconds since the epoch	*/
1901e72d8d2Sderaadt     unsigned short	millitm;	/* Field not used		*/
1911e72d8d2Sderaadt     short		timezone;
1921e72d8d2Sderaadt     short		dstflag;	/* Field not used		*/
1931e72d8d2Sderaadt };
1941e72d8d2Sderaadt #endif
1951e72d8d2Sderaadt 
1961e72d8d2Sderaadt #if !defined(HAVE_FTIME) && !defined(HAVE_TIMEZONE)
1971e72d8d2Sderaadt #if !defined(timezone)
1981e72d8d2Sderaadt extern long timezone;
1991e72d8d2Sderaadt #endif
2001e72d8d2Sderaadt #endif
2011e72d8d2Sderaadt 
2021e72d8d2Sderaadt 
2031e72d8d2Sderaadt /*
2041e72d8d2Sderaadt **  MAXPATHLEN and PATH_MAX
2051e72d8d2Sderaadt **
2061e72d8d2Sderaadt **     On most systems MAXPATHLEN is defined in sys/param.h to be 1024. Of
2071e72d8d2Sderaadt **     those that this is not true, again most define PATH_MAX in limits.h
2081e72d8d2Sderaadt **     or sys/limits.h which usually gets included by limits.h. On the few
2091e72d8d2Sderaadt **     remaining systems that neither statement is true, _POSIX_PATH_MAX
2101e72d8d2Sderaadt **     is defined.
2111e72d8d2Sderaadt **
2121e72d8d2Sderaadt **     So:
2131e72d8d2Sderaadt **         1. If PATH_MAX is defined just use it.
2141e72d8d2Sderaadt **         2. If MAXPATHLEN is defined but not PATH_MAX, then define
2151e72d8d2Sderaadt **            PATH_MAX in terms of MAXPATHLEN.
2161e72d8d2Sderaadt **         3. If neither is defined, include limits.h and check for
2171e72d8d2Sderaadt **            PATH_MAX again.
2181e72d8d2Sderaadt **         3.1 If we now have PATHSIZE, define PATH_MAX in terms of that.
2191e72d8d2Sderaadt **             and ignore the rest.  Since _POSIX_PATH_MAX (checked for
2201e72d8d2Sderaadt **             next) is the *most* restrictive (smallest) value, if we
2211e72d8d2Sderaadt **             trust _POSIX_PATH_MAX, several of our buffers are too small.
2221e72d8d2Sderaadt **         4. If PATH_MAX is still not defined but _POSIX_PATH_MAX is,
2231e72d8d2Sderaadt **            then define PATH_MAX in terms of _POSIX_PATH_MAX.
2241e72d8d2Sderaadt **         5. And if even _POSIX_PATH_MAX doesn't exist just put in
2251e72d8d2Sderaadt **            a reasonable value.
2261e72d8d2Sderaadt **         *. All in all, this is an excellent argument for using pathconf()
2271e72d8d2Sderaadt **            when at all possible.  Or better yet, dynamically allocate
2281e72d8d2Sderaadt **            our buffers and use getcwd() not getwd().
2291e72d8d2Sderaadt **
2301e72d8d2Sderaadt **     This works on:
2311e72d8d2Sderaadt **         Sun Sparc 10        SunOS 4.1.3  &  Solaris 1.2
2321e72d8d2Sderaadt **         HP 9000/700         HP/UX 8.07   &  HP/UX 9.01
2331e72d8d2Sderaadt **         Tektronix XD88/10   UTekV 3.2e
2341e72d8d2Sderaadt **         IBM RS6000          AIX 3.2
2351e72d8d2Sderaadt **         Dec Alpha           OSF 1 ????
2361e72d8d2Sderaadt **         Intel 386           BSDI BSD/386
2371e72d8d2Sderaadt **         Intel 386           SCO OpenServer Release 5
2381e72d8d2Sderaadt **         Apollo              Domain 10.4
2391e72d8d2Sderaadt **         NEC                 SVR4
2401e72d8d2Sderaadt */
2411e72d8d2Sderaadt 
2421e72d8d2Sderaadt /* On MOST systems this will get you MAXPATHLEN.
2431e72d8d2Sderaadt    Windows NT doesn't have this file, tho.  */
2441e72d8d2Sderaadt #ifdef HAVE_SYS_PARAM_H
2451e72d8d2Sderaadt #include <sys/param.h>
2461e72d8d2Sderaadt #endif
2471e72d8d2Sderaadt 
2481e72d8d2Sderaadt #ifndef PATH_MAX
2491e72d8d2Sderaadt #  ifdef MAXPATHLEN
2501e72d8d2Sderaadt #    define PATH_MAX                 MAXPATHLEN
2511e72d8d2Sderaadt #  else
2521e72d8d2Sderaadt #    include <limits.h>
2531e72d8d2Sderaadt #    ifndef PATH_MAX
2541e72d8d2Sderaadt #      ifdef PATHSIZE
2551e72d8d2Sderaadt #         define PATH_MAX               PATHSIZE
2561e72d8d2Sderaadt #      else /* no PATHSIZE */
2571e72d8d2Sderaadt #        ifdef _POSIX_PATH_MAX
2581e72d8d2Sderaadt #          define PATH_MAX             _POSIX_PATH_MAX
2591e72d8d2Sderaadt #        else
2601e72d8d2Sderaadt #          define PATH_MAX             1024
2611e72d8d2Sderaadt #        endif  /* no _POSIX_PATH_MAX */
2621e72d8d2Sderaadt #      endif  /* no PATHSIZE */
2631e72d8d2Sderaadt #    endif /* no PATH_MAX   */
2641e72d8d2Sderaadt #  endif  /* MAXPATHLEN */
2651e72d8d2Sderaadt #endif  /* PATH_MAX   */
2661e72d8d2Sderaadt 
2671e72d8d2Sderaadt 
2681e72d8d2Sderaadt /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h
2691e72d8d2Sderaadt    which doesn't define anything.  It would be cleaner to have configure
2701e72d8d2Sderaadt    check for struct utimbuf, but for now I'm checking NeXT here (so I don't
2711e72d8d2Sderaadt    have to debug the configure check across all the machines).  */
2721e72d8d2Sderaadt #if defined (HAVE_UTIME_H) && !defined (NeXT)
2731e72d8d2Sderaadt #  include <utime.h>
274*50bf276cStholo #else
275*50bf276cStholo #  if defined (HAVE_SYS_UTIME_H)
27613571821Stholo #    include <sys/utime.h>
2771e72d8d2Sderaadt #  else
2781e72d8d2Sderaadt #    ifndef ALTOS
2791e72d8d2Sderaadt struct utimbuf
2801e72d8d2Sderaadt {
2811e72d8d2Sderaadt   long actime;
2821e72d8d2Sderaadt   long modtime;
2831e72d8d2Sderaadt };
2841e72d8d2Sderaadt #    endif
2851e72d8d2Sderaadt int utime ();
2861e72d8d2Sderaadt #  endif
287*50bf276cStholo #endif
2881e72d8d2Sderaadt 
2891e72d8d2Sderaadt #if STDC_HEADERS || HAVE_STRING_H
2901e72d8d2Sderaadt #  include <string.h>
2911e72d8d2Sderaadt    /* An ANSI string.h and pre-ANSI memory.h might conflict. */
2921e72d8d2Sderaadt #  if !STDC_HEADERS && HAVE_MEMORY_H
2931e72d8d2Sderaadt #    include <memory.h>
2941e72d8d2Sderaadt #  endif /* not STDC_HEADERS and HAVE_MEMORY_H */
2951e72d8d2Sderaadt #else /* not STDC_HEADERS and not HAVE_STRING_H */
2961e72d8d2Sderaadt #  include <strings.h>
2971e72d8d2Sderaadt    /* memory.h and strings.h conflict on some systems. */
2981e72d8d2Sderaadt #endif /* not STDC_HEADERS and not HAVE_STRING_H */
2991e72d8d2Sderaadt 
300*50bf276cStholo #ifndef ERRNO_H_MISSING
3011e72d8d2Sderaadt #include <errno.h>
302*50bf276cStholo #endif
30313571821Stholo 
30413571821Stholo /* Not all systems set the same error code on a non-existent-file
30513571821Stholo    error.  This tries to ask the question somewhat portably.
30613571821Stholo    On systems that don't have ENOTEXIST, this should behave just like
30713571821Stholo    x == ENOENT.  "x" is probably errno, of course. */
30813571821Stholo 
30913571821Stholo #ifdef ENOTEXIST
31013571821Stholo #  ifdef EOS2ERR
31113571821Stholo #    define existence_error(x) \
31213571821Stholo      (((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
31313571821Stholo #  else
31413571821Stholo #    define existence_error(x) \
31513571821Stholo      (((x) == ENOTEXIST) || ((x) == ENOENT))
31613571821Stholo #  endif
31713571821Stholo #else
318c2c61682Stholo #  ifdef EVMSERR
319c2c61682Stholo #     define existence_error(x) \
320c2c61682Stholo ((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
321c2c61682Stholo #  else
32213571821Stholo #    define existence_error(x) ((x) == ENOENT)
32313571821Stholo #  endif
324c2c61682Stholo #endif
32513571821Stholo 
32613571821Stholo 
3271e72d8d2Sderaadt #ifdef STDC_HEADERS
3281e72d8d2Sderaadt #include <stdlib.h>
3291e72d8d2Sderaadt #else
3301e72d8d2Sderaadt char *getenv ();
3311e72d8d2Sderaadt char *malloc ();
3321e72d8d2Sderaadt char *realloc ();
3331e72d8d2Sderaadt char *calloc ();
3341e72d8d2Sderaadt extern int errno;
3351e72d8d2Sderaadt #endif
3361e72d8d2Sderaadt 
337c2c61682Stholo /* SunOS4 apparently does not define this in stdlib.h.  */
338c2c61682Stholo #ifndef EXIT_FAILURE
339c2c61682Stholo #define EXIT_FAILURE 1
340c2c61682Stholo #endif
341c2c61682Stholo 
3421e72d8d2Sderaadt #if defined(USG) || defined(POSIX)
3431e72d8d2Sderaadt char *getcwd ();
3441e72d8d2Sderaadt #else
3451e72d8d2Sderaadt char *getwd ();
3461e72d8d2Sderaadt #endif
3471e72d8d2Sderaadt 
34813571821Stholo /* check for POSIX signals */
34913571821Stholo #if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
35013571821Stholo # define POSIX_SIGNALS
35113571821Stholo #endif
35213571821Stholo 
35313571821Stholo /* MINIX 1.6 doesn't properly support sigaction */
35413571821Stholo #if defined(_MINIX)
35513571821Stholo # undef POSIX_SIGNALS
35613571821Stholo #endif
35713571821Stholo 
35813571821Stholo /* If !POSIX, try for BSD.. Reason: 4.4BSD implements these as wrappers */
35913571821Stholo #if !defined(POSIX_SIGNALS)
36013571821Stholo # if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
36113571821Stholo #  define BSD_SIGNALS
36213571821Stholo # endif
36313571821Stholo #endif
36413571821Stholo 
36513571821Stholo /* Under OS/2, this must be included _after_ stdio.h; that's why we do
36613571821Stholo    it here. */
36713571821Stholo #ifdef USE_OWN_TCPIP_H
36813571821Stholo #include "tcpip.h"
36913571821Stholo #endif
37013571821Stholo 
3711e72d8d2Sderaadt #ifdef HAVE_FCNTL_H
3721e72d8d2Sderaadt #include <fcntl.h>
3731e72d8d2Sderaadt #else
3741e72d8d2Sderaadt #include <sys/file.h>
3751e72d8d2Sderaadt #endif
3761e72d8d2Sderaadt 
3771e72d8d2Sderaadt #ifndef SEEK_SET
3781e72d8d2Sderaadt #define SEEK_SET 0
3791e72d8d2Sderaadt #define SEEK_CUR 1
3801e72d8d2Sderaadt #define SEEK_END 2
3811e72d8d2Sderaadt #endif
3821e72d8d2Sderaadt 
3831e72d8d2Sderaadt #ifndef F_OK
3841e72d8d2Sderaadt #define F_OK 0
3851e72d8d2Sderaadt #define X_OK 1
3861e72d8d2Sderaadt #define W_OK 2
3871e72d8d2Sderaadt #define R_OK 4
3881e72d8d2Sderaadt #endif
3891e72d8d2Sderaadt 
3901e72d8d2Sderaadt #if HAVE_DIRENT_H
3911e72d8d2Sderaadt # include <dirent.h>
3921e72d8d2Sderaadt # define NAMLEN(dirent) strlen((dirent)->d_name)
3931e72d8d2Sderaadt #else
3941e72d8d2Sderaadt # define dirent direct
3951e72d8d2Sderaadt # define NAMLEN(dirent) (dirent)->d_namlen
3961e72d8d2Sderaadt # if HAVE_SYS_NDIR_H
3971e72d8d2Sderaadt #  include <sys/ndir.h>
3981e72d8d2Sderaadt # endif
3991e72d8d2Sderaadt # if HAVE_SYS_DIR_H
4001e72d8d2Sderaadt #  include <sys/dir.h>
4011e72d8d2Sderaadt # endif
4021e72d8d2Sderaadt # if HAVE_NDIR_H
4031e72d8d2Sderaadt #  include <ndir.h>
4041e72d8d2Sderaadt # endif
4051e72d8d2Sderaadt #endif
4061e72d8d2Sderaadt 
4071e72d8d2Sderaadt /* Convert B 512-byte blocks to kilobytes if K is nonzero,
4081e72d8d2Sderaadt    otherwise return it unchanged. */
4091e72d8d2Sderaadt #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
4101e72d8d2Sderaadt 
4111e72d8d2Sderaadt #ifndef S_ISLNK
4121e72d8d2Sderaadt #define lstat stat
4131e72d8d2Sderaadt #endif
4141e72d8d2Sderaadt 
4151e72d8d2Sderaadt /*
4161e72d8d2Sderaadt  * Some UNIX distributions don't include these in their stat.h Defined here
4171e72d8d2Sderaadt  * because "config.h" is always included last.
4181e72d8d2Sderaadt  */
4191e72d8d2Sderaadt #ifndef S_IWRITE
4201e72d8d2Sderaadt #define	S_IWRITE	0000200		/* write permission, owner */
4211e72d8d2Sderaadt #endif
4221e72d8d2Sderaadt #ifndef S_IWGRP
4231e72d8d2Sderaadt #define	S_IWGRP		0000020		/* write permission, grougroup */
4241e72d8d2Sderaadt #endif
4251e72d8d2Sderaadt #ifndef S_IWOTH
4261e72d8d2Sderaadt #define	S_IWOTH		0000002		/* write permission, other */
4271e72d8d2Sderaadt #endif
4281e72d8d2Sderaadt 
429*50bf276cStholo /* Under non-UNIX operating systems (MS-DOS, WinNT, MacOS), many filesystem
430*50bf276cStholo    calls take  only one argument; permission is handled very differently on
431*50bf276cStholo    those systems than in Unix.  So we leave such systems a hook on which they
432*50bf276cStholo    can hang their own definitions.  */
433*50bf276cStholo 
434*50bf276cStholo #ifndef CVS_ACCESS
435*50bf276cStholo #define CVS_ACCESS access
436*50bf276cStholo #endif
437*50bf276cStholo 
438*50bf276cStholo #ifndef CVS_CHDIR
439*50bf276cStholo #define CVS_CHDIR chdir
440*50bf276cStholo #endif
441*50bf276cStholo 
442*50bf276cStholo #ifndef CVS_CREAT
443*50bf276cStholo #define CVS_CREAT creat
444*50bf276cStholo #endif
445*50bf276cStholo 
446*50bf276cStholo #ifndef CVS_FOPEN
447*50bf276cStholo #define CVS_FOPEN fopen
448*50bf276cStholo #endif
449*50bf276cStholo 
4501e72d8d2Sderaadt #ifndef CVS_MKDIR
4511e72d8d2Sderaadt #define CVS_MKDIR mkdir
4521e72d8d2Sderaadt #endif
4531e72d8d2Sderaadt 
454*50bf276cStholo #ifndef CVS_OPEN
455*50bf276cStholo #define CVS_OPEN open
456*50bf276cStholo #endif
457*50bf276cStholo 
458*50bf276cStholo #ifndef CVS_OPENDIR
459*50bf276cStholo #define CVS_OPENDIR opendir
460*50bf276cStholo #endif
461*50bf276cStholo 
462*50bf276cStholo #ifndef CVS_RENAME
463*50bf276cStholo #define CVS_RENAME rename
464*50bf276cStholo #endif
465*50bf276cStholo 
466*50bf276cStholo #ifndef CVS_RMDIR
467*50bf276cStholo #define CVS_RMDIR rmdir
468*50bf276cStholo #endif
469*50bf276cStholo 
470*50bf276cStholo #ifndef CVS_STAT
471*50bf276cStholo #define CVS_STAT stat
472*50bf276cStholo #endif
473*50bf276cStholo 
474*50bf276cStholo #ifndef CVS_UNLINK
475*50bf276cStholo #define CVS_UNLINK unlink
476*50bf276cStholo #endif
477*50bf276cStholo 
4781e72d8d2Sderaadt /* Some file systems are case-insensitive.  If FOLD_FN_CHAR is
4791e72d8d2Sderaadt    #defined, it maps the character C onto its "canonical" form.  In a
4801e72d8d2Sderaadt    case-insensitive system, it would map all alphanumeric characters
4811e72d8d2Sderaadt    to lower case.  Under Windows NT, / and \ are both path component
4821e72d8d2Sderaadt    separators, so FOLD_FN_CHAR would map them both to /.  */
4831e72d8d2Sderaadt #ifndef FOLD_FN_CHAR
4841e72d8d2Sderaadt #define FOLD_FN_CHAR(c) (c)
4851e72d8d2Sderaadt #define fnfold(filename) (filename)
4861e72d8d2Sderaadt #define fncmp strcmp
4871e72d8d2Sderaadt #endif
4881e72d8d2Sderaadt 
4891e72d8d2Sderaadt /* Different file systems have different path component separators.
4901e72d8d2Sderaadt    For the VMS port we might need to abstract further back than this.  */
4911e72d8d2Sderaadt #ifndef ISDIRSEP
4921e72d8d2Sderaadt #define ISDIRSEP(c) ((c) == '/')
4931e72d8d2Sderaadt #endif
4941e72d8d2Sderaadt 
4951e72d8d2Sderaadt 
4961e72d8d2Sderaadt /* On some systems, lines in text files should be terminated with CRLF,
4971e72d8d2Sderaadt    not just LF, and the read and write routines do this translation
4981e72d8d2Sderaadt    for you.  LINES_CRLF_TERMINATED is #defined on such systems.
4991e72d8d2Sderaadt    - OPEN_BINARY is the flag to pass to the open function for
5001e72d8d2Sderaadt      untranslated I/O.
5011e72d8d2Sderaadt    - FOPEN_BINARY_READ is the string to pass to fopen to get
5021e72d8d2Sderaadt      untranslated reading.
5031e72d8d2Sderaadt    - FOPEN_BINARY_WRITE is the string to pass to fopen to get
5041e72d8d2Sderaadt      untranslated writing.  */
5051e72d8d2Sderaadt #if LINES_CRLF_TERMINATED
5061e72d8d2Sderaadt #define OPEN_BINARY (O_BINARY)
5071e72d8d2Sderaadt #define FOPEN_BINARY_READ ("rb")
5081e72d8d2Sderaadt #define FOPEN_BINARY_WRITE ("wb")
5091e72d8d2Sderaadt #else
5101e72d8d2Sderaadt #define OPEN_BINARY (0)
5111e72d8d2Sderaadt #define FOPEN_BINARY_READ ("r")
5121e72d8d2Sderaadt #define FOPEN_BINARY_WRITE ("w")
5131e72d8d2Sderaadt #endif
514