1 /* System dependent declarations. 2 Copyright (C) 1988, 1989, 1992, 1993, 1994 Free Software Foundation, Inc. 3 4 This file is part of GNU DIFF. 5 6 GNU DIFF is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU DIFF is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU DIFF; see the file COPYING. If not, write to 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 19 20 /* We must define `volatile' and `const' first (the latter inside config.h), 21 so that they're used consistently in all system includes. */ 22 #if !__STDC__ 23 #ifndef volatile 24 #define volatile 25 #endif 26 #endif 27 #include <config.h> 28 29 #include <sys/types.h> 30 #include <sys/stat.h> 31 32 #if __STDC__ 33 #define PARAMS(args) args 34 #define VOID void 35 #else 36 #define PARAMS(args) () 37 #define VOID char 38 #endif 39 40 #if STAT_MACROS_BROKEN 41 #undef S_ISBLK 42 #undef S_ISCHR 43 #undef S_ISDIR 44 #undef S_ISFIFO 45 #undef S_ISREG 46 #undef S_ISSOCK 47 #endif 48 #ifndef S_ISDIR 49 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 50 #endif 51 #ifndef S_ISREG 52 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 53 #endif 54 #if !defined(S_ISBLK) && defined(S_IFBLK) 55 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 56 #endif 57 #if !defined(S_ISCHR) && defined(S_IFCHR) 58 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 59 #endif 60 #if !defined(S_ISFIFO) && defined(S_IFFIFO) 61 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO) 62 #endif 63 #if !defined(S_ISSOCK) && defined(S_IFSOCK) 64 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) 65 #endif 66 67 #if HAVE_UNISTD_H 68 #include <unistd.h> 69 #endif 70 71 #ifndef SEEK_SET 72 #define SEEK_SET 0 73 #endif 74 #ifndef SEEK_CUR 75 #define SEEK_CUR 1 76 #endif 77 78 #ifndef STDIN_FILENO 79 #define STDIN_FILENO 0 80 #endif 81 #ifndef STDOUT_FILENO 82 #define STDOUT_FILENO 1 83 #endif 84 #ifndef STDERR_FILENO 85 #define STDERR_FILENO 2 86 #endif 87 88 #if HAVE_TIME_H 89 #include <time.h> 90 #else 91 #include <sys/time.h> 92 #endif 93 94 #if HAVE_FCNTL_H 95 #include <fcntl.h> 96 #else 97 #if HAVE_SYS_FILE_H 98 #include <sys/file.h> 99 #endif 100 #endif 101 102 #if !HAVE_DUP2 103 #define dup2(f,t) (close (t), fcntl (f,F_DUPFD,t)) 104 #endif 105 106 #ifndef O_RDONLY 107 #define O_RDONLY 0 108 #endif 109 110 #if HAVE_SYS_WAIT_H 111 #include <sys/wait.h> 112 #endif 113 #ifndef WEXITSTATUS 114 #define WEXITSTATUS(stat_val) ((unsigned) (stat_val) >> 8) 115 #endif 116 #ifndef WIFEXITED 117 #define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 118 #endif 119 120 #ifndef STAT_BLOCKSIZE 121 #if HAVE_ST_BLKSIZE 122 #define STAT_BLOCKSIZE(s) (s).st_blksize 123 #else 124 #define STAT_BLOCKSIZE(s) (8 * 1024) 125 #endif 126 #endif 127 128 #if HAVE_DIRENT_H 129 # include <dirent.h> 130 # define NAMLEN(dirent) strlen((dirent)->d_name) 131 #else 132 # define dirent direct 133 # define NAMLEN(dirent) ((dirent)->d_namlen) 134 # if HAVE_SYS_NDIR_H 135 # include <sys/ndir.h> 136 # endif 137 # if HAVE_SYS_DIR_H 138 # include <sys/dir.h> 139 # endif 140 # if HAVE_NDIR_H 141 # include <ndir.h> 142 # endif 143 #endif 144 145 #if HAVE_VFORK_H 146 #include <vfork.h> 147 #endif 148 149 #if HAVE_STDLIB_H 150 #include <stdlib.h> 151 #else 152 VOID *malloc (); 153 VOID *realloc (); 154 #endif 155 #ifndef getenv 156 char *getenv (); 157 #endif 158 159 #if HAVE_LIMITS_H 160 #include <limits.h> 161 #endif 162 #ifndef INT_MAX 163 #define INT_MAX 2147483647 164 #endif 165 #ifndef CHAR_BIT 166 #define CHAR_BIT 8 167 #endif 168 169 #if STDC_HEADERS || HAVE_STRING_H 170 # include <string.h> 171 # ifndef bzero 172 # define bzero(s, n) memset (s, 0, n) 173 # endif 174 #else 175 # if !HAVE_STRCHR 176 # define strchr index 177 # define strrchr rindex 178 # endif 179 char *strchr (), *strrchr (); 180 # if !HAVE_MEMCHR 181 # define memcmp(s1, s2, n) bcmp (s1, s2, n) 182 # define memcpy(d, s, n) bcopy (s, d, n) 183 void *memchr (); 184 # endif 185 #endif 186 187 #include <ctype.h> 188 /* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given 189 as an argument to <ctype.h> macros like `isspace'. */ 190 #if STDC_HEADERS 191 #define CTYPE_DOMAIN(c) 1 192 #else 193 #define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177) 194 #endif 195 #ifndef ISPRINT 196 #define ISPRINT(c) (CTYPE_DOMAIN (c) && isprint (c)) 197 #endif 198 #ifndef ISSPACE 199 #define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c)) 200 #endif 201 #ifndef ISUPPER 202 #define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c)) 203 #endif 204 205 #ifndef ISDIGIT 206 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) 207 #endif 208 209 #include <errno.h> 210 #if !STDC_HEADERS 211 extern int errno; 212 #endif 213 214 #ifdef min 215 #undef min 216 #endif 217 #ifdef max 218 #undef max 219 #endif 220 #define min(a,b) ((a) <= (b) ? (a) : (b)) 221 #define max(a,b) ((a) >= (b) ? (a) : (b)) 222 223 /* This section contains Posix-compliant defaults for macros 224 that are meant to be overridden by hand in config.h as needed. */ 225 226 #ifndef filename_cmp 227 #define filename_cmp(a, b) strcmp (a, b) 228 #endif 229 230 #ifndef filename_lastdirchar 231 #define filename_lastdirchar(filename) strrchr (filename, '/') 232 #endif 233 234 #ifndef HAVE_FORK 235 #define HAVE_FORK 1 236 #endif 237 238 #ifndef HAVE_SETMODE 239 #define HAVE_SETMODE 0 240 #endif 241 242 #ifndef initialize_main 243 #define initialize_main(argcp, argvp) 244 #endif 245 246 /* Do struct stat *S, *T describe the same file? Answer -1 if unknown. */ 247 #ifndef same_file 248 /* #define same_file(s,t) ((s)->st_ino==(t)->st_ino && (s)->st_dev==(t)->st_dev) */ 249 #define same_file(s,t) 0 250 #endif 251 252 /* Place into Q a quoted version of A suitable for `popen' or `system', 253 incrementing Q and junking A. 254 Do not increment Q by more than 4 * strlen (A) + 2. */ 255 #ifndef SYSTEM_QUOTE_ARG 256 #define SYSTEM_QUOTE_ARG(q, a) \ 257 { \ 258 *(q)++ = '\''; \ 259 for (; *(a); *(q)++ = *(a)++) \ 260 if (*(a) == '\'') \ 261 { \ 262 *(q)++ = '\''; \ 263 *(q)++ = '\\'; \ 264 *(q)++ = '\''; \ 265 } \ 266 *(q)++ = '\''; \ 267 } 268 #endif 269 #ifndef FOLD_FN_CHAR 270 #define FOLD_FN_CHAR(c) (c) 271 #define fnfold(filename) (filename) 272 #define fncmp strcmp 273 #endif 274