1 /* system-dependent definitions for CVS. 2 Copyright (C) 1989-1992 Free Software Foundation, Inc. 3 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) 7 any later version. 8 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. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 18 /* $CVSid: @(#)system.h 1.18 94/09/25 $ */ 19 20 #ifdef __GNUC__ 21 #ifndef alloca 22 #define alloca __builtin_alloca 23 #endif 24 #else 25 #ifdef HAVE_ALLOCA_H 26 #include <alloca.h> 27 #else 28 #ifdef _AIX 29 /* AIX alloca decl has to be the first thing in the file, bletch! */ 30 #pragma alloca 31 #else /* not _AIX */ 32 char *alloca (); 33 #endif /* not _AIX */ 34 #endif /* not HAVE_ALLOCA_H */ 35 #endif /* not __GNUS__ */ 36 37 #include <sys/types.h> 38 #include <sys/stat.h> 39 40 #ifdef STAT_MACROS_BROKEN 41 #undef S_ISBLK 42 #undef S_ISCHR 43 #undef S_ISDIR 44 #undef S_ISREG 45 #undef S_ISFIFO 46 #undef S_ISLNK 47 #undef S_ISSOCK 48 #undef S_ISMPB 49 #undef S_ISMPC 50 #undef S_ISNWK 51 #endif 52 53 #if !defined(S_ISBLK) && defined(S_IFBLK) 54 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 55 #endif 56 #if !defined(S_ISCHR) && defined(S_IFCHR) 57 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 58 #endif 59 #if !defined(S_ISDIR) && defined(S_IFDIR) 60 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 61 #endif 62 #if !defined(S_ISREG) && defined(S_IFREG) 63 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 64 #endif 65 #if !defined(S_ISFIFO) && defined(S_IFIFO) 66 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 67 #endif 68 #if !defined(S_ISLNK) && defined(S_IFLNK) 69 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 70 #endif 71 #if !defined(S_ISSOCK) && defined(S_IFSOCK) 72 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) 73 #endif 74 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */ 75 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) 76 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) 77 #endif 78 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ 79 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) 80 #endif 81 #if !defined(HAVE_MKFIFO) 82 #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0)) 83 #endif 84 85 #ifndef S_IRUSR 86 #define S_IRUSR 0400 87 #define S_IWUSR 0200 88 #define S_IXUSR 0100 89 /* Read, write, and execute by owner. */ 90 #define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) 91 92 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */ 93 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */ 94 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */ 95 /* Read, write, and execute by group. */ 96 #define S_IRWXG (S_IRWXU >> 3) 97 98 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */ 99 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */ 100 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */ 101 /* Read, write, and execute by others. */ 102 #define S_IRWXO (S_IRWXG >> 3) 103 #endif 104 105 #if defined(POSIX) || defined(HAVE_UNISTD_H) 106 #include <unistd.h> 107 #include <limits.h> 108 #else 109 off_t lseek (); 110 #endif 111 112 #if TIME_WITH_SYS_TIME 113 # include <sys/time.h> 114 # include <time.h> 115 #else 116 # if HAVE_SYS_TIME_H 117 # include <sys/time.h> 118 # else 119 # include <time.h> 120 # endif 121 #endif 122 123 #ifdef HAVE_IO_H 124 #include <io.h> 125 #endif 126 127 #ifdef HAVE_DIRECT_H 128 #include <direct.h> 129 #endif 130 131 #ifdef timezone 132 #undef timezone /* needed for sgi */ 133 #endif 134 135 #ifdef HAVE_SYS_TIMEB_H 136 #include <sys/timeb.h> 137 #else 138 struct timeb { 139 time_t time; /* Seconds since the epoch */ 140 unsigned short millitm; /* Field not used */ 141 short timezone; 142 short dstflag; /* Field not used */ 143 }; 144 #endif 145 146 #if !defined(HAVE_FTIME) && !defined(HAVE_TIMEZONE) 147 #if !defined(timezone) 148 extern long timezone; 149 #endif 150 #endif 151 152 153 /* 154 ** MAXPATHLEN and PATH_MAX 155 ** 156 ** On most systems MAXPATHLEN is defined in sys/param.h to be 1024. Of 157 ** those that this is not true, again most define PATH_MAX in limits.h 158 ** or sys/limits.h which usually gets included by limits.h. On the few 159 ** remaining systems that neither statement is true, _POSIX_PATH_MAX 160 ** is defined. 161 ** 162 ** So: 163 ** 1. If PATH_MAX is defined just use it. 164 ** 2. If MAXPATHLEN is defined but not PATH_MAX, then define 165 ** PATH_MAX in terms of MAXPATHLEN. 166 ** 3. If neither is defined, include limits.h and check for 167 ** PATH_MAX again. 168 ** 3.1 If we now have PATHSIZE, define PATH_MAX in terms of that. 169 ** and ignore the rest. Since _POSIX_PATH_MAX (checked for 170 ** next) is the *most* restrictive (smallest) value, if we 171 ** trust _POSIX_PATH_MAX, several of our buffers are too small. 172 ** 4. If PATH_MAX is still not defined but _POSIX_PATH_MAX is, 173 ** then define PATH_MAX in terms of _POSIX_PATH_MAX. 174 ** 5. And if even _POSIX_PATH_MAX doesn't exist just put in 175 ** a reasonable value. 176 ** *. All in all, this is an excellent argument for using pathconf() 177 ** when at all possible. Or better yet, dynamically allocate 178 ** our buffers and use getcwd() not getwd(). 179 ** 180 ** This works on: 181 ** Sun Sparc 10 SunOS 4.1.3 & Solaris 1.2 182 ** HP 9000/700 HP/UX 8.07 & HP/UX 9.01 183 ** Tektronix XD88/10 UTekV 3.2e 184 ** IBM RS6000 AIX 3.2 185 ** Dec Alpha OSF 1 ???? 186 ** Intel 386 BSDI BSD/386 187 ** Intel 386 SCO OpenServer Release 5 188 ** Apollo Domain 10.4 189 ** NEC SVR4 190 */ 191 192 /* On MOST systems this will get you MAXPATHLEN. 193 Windows NT doesn't have this file, tho. */ 194 #ifdef HAVE_SYS_PARAM_H 195 #include <sys/param.h> 196 #endif 197 198 #ifndef PATH_MAX 199 # ifdef MAXPATHLEN 200 # define PATH_MAX MAXPATHLEN 201 # else 202 # include <limits.h> 203 # ifndef PATH_MAX 204 # ifdef PATHSIZE 205 # define PATH_MAX PATHSIZE 206 # else /* no PATHSIZE */ 207 # ifdef _POSIX_PATH_MAX 208 # define PATH_MAX _POSIX_PATH_MAX 209 # else 210 # define PATH_MAX 1024 211 # endif /* no _POSIX_PATH_MAX */ 212 # endif /* no PATHSIZE */ 213 # endif /* no PATH_MAX */ 214 # endif /* MAXPATHLEN */ 215 #endif /* PATH_MAX */ 216 217 218 /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h 219 which doesn't define anything. It would be cleaner to have configure 220 check for struct utimbuf, but for now I'm checking NeXT here (so I don't 221 have to debug the configure check across all the machines). */ 222 #if defined (HAVE_UTIME_H) && !defined (NeXT) 223 #include <utime.h> 224 #else 225 #ifndef ALTOS 226 struct utimbuf 227 { 228 long actime; 229 long modtime; 230 }; 231 #endif 232 int utime (); 233 #endif 234 235 #if STDC_HEADERS || HAVE_STRING_H 236 #include <string.h> 237 /* An ANSI string.h and pre-ANSI memory.h might conflict. */ 238 #if !STDC_HEADERS && HAVE_MEMORY_H 239 #include <memory.h> 240 #endif /* not STDC_HEADERS and HAVE_MEMORY_H */ 241 242 #ifndef index 243 #define index strchr 244 #endif /* index */ 245 246 #ifndef rindex 247 #define rindex strrchr 248 #endif /* rindex */ 249 250 #ifndef bcmp 251 #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) 252 #endif /* bcmp */ 253 254 #ifndef bzero 255 #define bzero(s, n) memset ((s), 0, (n)) 256 #endif /* bzero */ 257 258 #else /* not STDC_HEADERS and not HAVE_STRING_H */ 259 #include <strings.h> 260 /* memory.h and strings.h conflict on some systems. */ 261 #endif /* not STDC_HEADERS and not HAVE_STRING_H */ 262 263 #include <errno.h> 264 #ifdef STDC_HEADERS 265 #include <stdlib.h> 266 #else 267 char *getenv (); 268 char *malloc (); 269 char *realloc (); 270 char *calloc (); 271 extern int errno; 272 #endif 273 274 #if defined(USG) || defined(POSIX) 275 char *getcwd (); 276 #else 277 char *getwd (); 278 #endif 279 280 #ifdef HAVE_FCNTL_H 281 #include <fcntl.h> 282 #else 283 #include <sys/file.h> 284 #endif 285 286 #ifndef SEEK_SET 287 #define SEEK_SET 0 288 #define SEEK_CUR 1 289 #define SEEK_END 2 290 #endif 291 292 #ifndef F_OK 293 #define F_OK 0 294 #define X_OK 1 295 #define W_OK 2 296 #define R_OK 4 297 #endif 298 299 #if HAVE_DIRENT_H 300 # include <dirent.h> 301 # define NAMLEN(dirent) strlen((dirent)->d_name) 302 #else 303 # define dirent direct 304 # define NAMLEN(dirent) (dirent)->d_namlen 305 # if HAVE_SYS_NDIR_H 306 # include <sys/ndir.h> 307 # endif 308 # if HAVE_SYS_DIR_H 309 # include <sys/dir.h> 310 # endif 311 # if HAVE_NDIR_H 312 # include <ndir.h> 313 # endif 314 #endif 315 316 /* Convert B 512-byte blocks to kilobytes if K is nonzero, 317 otherwise return it unchanged. */ 318 #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b)) 319 320 #ifndef S_ISLNK 321 #define lstat stat 322 #endif 323 324 /* 325 * Some UNIX distributions don't include these in their stat.h Defined here 326 * because "config.h" is always included last. 327 */ 328 #ifndef S_IWRITE 329 #define S_IWRITE 0000200 /* write permission, owner */ 330 #endif 331 #ifndef S_IWGRP 332 #define S_IWGRP 0000020 /* write permission, grougroup */ 333 #endif 334 #ifndef S_IWOTH 335 #define S_IWOTH 0000002 /* write permission, other */ 336 #endif 337 338 339 /* Under MS-DOS and its derivatives (like Windows NT), mkdir takes only one 340 argument; permission is handled very differently on those systems than in 341 in Unix. So we leave such systems a hook on which they can hang their 342 own definitions. */ 343 #ifndef CVS_MKDIR 344 #define CVS_MKDIR mkdir 345 #endif 346 347 /* Some file systems are case-insensitive. If FOLD_FN_CHAR is 348 #defined, it maps the character C onto its "canonical" form. In a 349 case-insensitive system, it would map all alphanumeric characters 350 to lower case. Under Windows NT, / and \ are both path component 351 separators, so FOLD_FN_CHAR would map them both to /. */ 352 #ifndef FOLD_FN_CHAR 353 #define FOLD_FN_CHAR(c) (c) 354 #define fnfold(filename) (filename) 355 #define fncmp strcmp 356 #endif 357 358 /* Different file systems have different path component separators. 359 For the VMS port we might need to abstract further back than this. */ 360 #ifndef ISDIRSEP 361 #define ISDIRSEP(c) ((c) == '/') 362 #endif 363 364 365 /* On some systems, lines in text files should be terminated with CRLF, 366 not just LF, and the read and write routines do this translation 367 for you. LINES_CRLF_TERMINATED is #defined on such systems. 368 - OPEN_BINARY is the flag to pass to the open function for 369 untranslated I/O. 370 - FOPEN_BINARY_READ is the string to pass to fopen to get 371 untranslated reading. 372 - FOPEN_BINARY_WRITE is the string to pass to fopen to get 373 untranslated writing. */ 374 #if LINES_CRLF_TERMINATED 375 #define OPEN_BINARY (O_BINARY) 376 #define FOPEN_BINARY_READ ("rb") 377 #define FOPEN_BINARY_WRITE ("wb") 378 #else 379 #define OPEN_BINARY (0) 380 #define FOPEN_BINARY_READ ("r") 381 #define FOPEN_BINARY_WRITE ("w") 382 #endif 383