178189Sbrian/* System dependent declarations. 2330449Seadler Copyright (C) 1988, 1989, 1992, 1993, 1994 Free Software Foundation, Inc. 3330449Seadler 478189SbrianThis file is part of GNU DIFF. 578189Sbrian 678189SbrianGNU DIFF is free software; you can redistribute it and/or modify 778189Sbrianit under the terms of the GNU General Public License as published by 846686Sbrianthe Free Software Foundation; either version 2, or (at your option) 978189Sbrianany later version. 1078189Sbrian 1178189SbrianGNU DIFF is distributed in the hope that it will be useful, 1278189Sbrianbut WITHOUT ANY WARRANTY; without even the implied warranty of 1378189SbrianMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1478189SbrianGNU General Public License for more details. 1578189Sbrian 1678189Sbrian*/ 1746686Sbrian 1878189Sbrian/* We must define `volatile' and `const' first (the latter inside config.h), 1978189Sbrian so that they're used consistently in all system includes. */ 2078189Sbrian#if !__STDC__ 2178189Sbrian#ifndef volatile 2278189Sbrian#define volatile 2378189Sbrian#endif 2478189Sbrian#endif 2578189Sbrian#include <config.h> 2678189Sbrian 2778189Sbrian#include <sys/types.h> 2878189Sbrian#include <sys/stat.h> 2946686Sbrian 3050479Speter/* Note that PARAMS is just internal to the diff library; diffrun.h 3146686Sbrian has its own mechanism, which will hopefully be less likely to 3246686Sbrian conflict with the library's caller's namespace. */ 3346686Sbrian#if __STDC__ 3446686Sbrian#define PARAMS(args) args 3546686Sbrian#define VOID void 3646686Sbrian#else 3746686Sbrian#define PARAMS(args) () 3846686Sbrian#define VOID char 3946686Sbrian#endif 4081634Sbrian 4181634Sbrian#if STAT_MACROS_BROKEN 4281634Sbrian#undef S_ISBLK 4346686Sbrian#undef S_ISCHR 4446686Sbrian#undef S_ISDIR 4546686Sbrian#undef S_ISFIFO 4687544Sbrian#undef S_ISREG 4746686Sbrian#undef S_ISSOCK 4846686Sbrian#endif 4981634Sbrian#ifndef S_ISDIR 5081634Sbrian#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 5181634Sbrian#endif 5246686Sbrian#ifndef S_ISREG 5346686Sbrian#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 5446686Sbrian#endif 5546686Sbrian#if !defined(S_ISBLK) && defined(S_IFBLK) 5646686Sbrian#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 5746686Sbrian#endif 5846686Sbrian#if !defined(S_ISCHR) && defined(S_IFCHR) 5946686Sbrian#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 6046686Sbrian#endif 6146686Sbrian#if !defined(S_ISFIFO) && defined(S_IFFIFO) 6246686Sbrian#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO) 6346686Sbrian#endif 6446686Sbrian#if !defined(S_ISSOCK) && defined(S_IFSOCK) 6546686Sbrian#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) 6646686Sbrian#endif 67 68#if HAVE_UNISTD_H 69#include <unistd.h> 70#endif 71 72#ifndef SEEK_SET 73#define SEEK_SET 0 74#endif 75#ifndef SEEK_CUR 76#define SEEK_CUR 1 77#endif 78 79#ifndef STDIN_FILENO 80#define STDIN_FILENO 0 81#endif 82#ifndef STDOUT_FILENO 83#define STDOUT_FILENO 1 84#endif 85#ifndef STDERR_FILENO 86#define STDERR_FILENO 2 87#endif 88 89/* I believe that all relevant systems have 90 time.h. It is in ANSI, for example. The 91 code below looks quite bogus as I don't think 92 sys/time.h is ever a substitute for time.h; 93 it is something different. */ 94#define HAVE_TIME_H 1 95 96#if HAVE_TIME_H 97#include <time.h> 98#else 99#include <sys/time.h> 100#endif 101 102#if HAVE_FCNTL_H 103#include <fcntl.h> 104#else 105#if HAVE_SYS_FILE_H 106#include <sys/file.h> 107#endif 108#endif 109 110#ifndef O_RDONLY 111#define O_RDONLY 0 112#endif 113 114#if HAVE_SYS_WAIT_H 115#include <sys/wait.h> 116#endif 117#ifndef WEXITSTATUS 118#define WEXITSTATUS(stat_val) ((unsigned) (stat_val) >> 8) 119#endif 120#ifndef WIFEXITED 121#define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 122#endif 123 124#ifndef STAT_BLOCKSIZE 125#if HAVE_ST_BLKSIZE 126#define STAT_BLOCKSIZE(s) (s).st_blksize 127#else 128#define STAT_BLOCKSIZE(s) (8 * 1024) 129#endif 130#endif 131 132#if HAVE_DIRENT_H 133# include <dirent.h> 134# define NAMLEN(dirent) strlen((dirent)->d_name) 135#else 136# define dirent direct 137# define NAMLEN(dirent) ((dirent)->d_namlen) 138# if HAVE_SYS_NDIR_H 139# include <sys/ndir.h> 140# endif 141# if HAVE_SYS_DIR_H 142# include <sys/dir.h> 143# endif 144# if HAVE_NDIR_H 145# include <ndir.h> 146# endif 147#endif 148 149#if HAVE_VFORK_H 150#include <vfork.h> 151#endif 152 153#if HAVE_STDLIB_H || defined(STDC_HEADERS) 154#include <stdlib.h> 155#else 156VOID *malloc (); 157VOID *realloc (); 158#endif 159#ifndef getenv 160char *getenv (); 161#endif 162 163#if HAVE_LIMITS_H 164#include <limits.h> 165#endif 166#ifndef INT_MAX 167#define INT_MAX 2147483647 168#endif 169#ifndef CHAR_BIT 170#define CHAR_BIT 8 171#endif 172 173#if STDC_HEADERS || HAVE_STRING_H 174# include <string.h> 175# ifndef bzero 176# define bzero(s, n) memset (s, 0, n) 177# endif 178#else 179# if !HAVE_STRCHR 180# define strchr index 181# define strrchr rindex 182# endif 183char *strchr (), *strrchr (); 184# if !HAVE_MEMCHR 185# define memcmp(s1, s2, n) bcmp (s1, s2, n) 186# define memcpy(d, s, n) bcopy (s, d, n) 187void *memchr (); 188# endif 189#endif 190 191#include <ctype.h> 192/* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given 193 as an argument to <ctype.h> macros like `isspace'. */ 194#if STDC_HEADERS 195#define CTYPE_DOMAIN(c) 1 196#else 197#define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177) 198#endif 199#ifndef ISPRINT 200#define ISPRINT(c) (CTYPE_DOMAIN (c) && isprint (c)) 201#endif 202#ifndef ISSPACE 203#define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c)) 204#endif 205#ifndef ISUPPER 206#define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c)) 207#endif 208 209#ifndef ISDIGIT 210#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) 211#endif 212 213#include <errno.h> 214#if !STDC_HEADERS 215extern int errno; 216#endif 217 218#ifdef min 219#undef min 220#endif 221#ifdef max 222#undef max 223#endif 224#define min(a,b) ((a) <= (b) ? (a) : (b)) 225#define max(a,b) ((a) >= (b) ? (a) : (b)) 226 227/* This section contains Posix-compliant defaults for macros 228 that are meant to be overridden by hand in config.h as needed. */ 229 230#ifndef filename_cmp 231#define filename_cmp(a, b) strcmp (a, b) 232#endif 233 234#ifndef filename_lastdirchar 235#define filename_lastdirchar(filename) strrchr (filename, '/') 236#endif 237 238#ifndef HAVE_FORK 239#define HAVE_FORK 1 240#endif 241 242#ifndef HAVE_SETMODE 243#define HAVE_SETMODE 0 244#endif 245 246#ifndef initialize_main 247#define initialize_main(argcp, argvp) 248#endif 249 250/* Do struct stat *S, *T describe the same file? Answer -1 if unknown. */ 251#ifndef same_file 252#define same_file(s,t) ((s)->st_ino==(t)->st_ino && (s)->st_dev==(t)->st_dev) 253#endif 254 255/* Place into Q a quoted version of A suitable for `popen' or `system', 256 incrementing Q and junking A. 257 Do not increment Q by more than 4 * strlen (A) + 2. */ 258#ifndef SYSTEM_QUOTE_ARG 259#define SYSTEM_QUOTE_ARG(q, a) \ 260 { \ 261 *(q)++ = '\''; \ 262 for (; *(a); *(q)++ = *(a)++) \ 263 if (*(a) == '\'') \ 264 { \ 265 *(q)++ = '\''; \ 266 *(q)++ = '\\'; \ 267 *(q)++ = '\''; \ 268 } \ 269 *(q)++ = '\''; \ 270 } 271#endif 272 273/* these come from CVS's lib/system.h, but I wasn't sure how to include that 274 * properly or even if I really should 275 */ 276#ifndef CVS_OPENDIR 277#define CVS_OPENDIR opendir 278#endif 279#ifndef CVS_READDIR 280#define CVS_READDIR readdir 281#endif 282#ifndef CVS_CLOSEDIR 283#define CVS_CLOSEDIR closedir 284#endif 285