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