12286d8edStholo /* System dependent declarations. 22286d8edStholo Copyright (C) 1988, 1989, 1992, 1993, 1994 Free Software Foundation, Inc. 32286d8edStholo 42286d8edStholo This file is part of GNU DIFF. 52286d8edStholo 62286d8edStholo GNU DIFF is free software; you can redistribute it and/or modify 72286d8edStholo it under the terms of the GNU General Public License as published by 82286d8edStholo the Free Software Foundation; either version 2, or (at your option) 92286d8edStholo any later version. 102286d8edStholo 112286d8edStholo GNU DIFF is distributed in the hope that it will be useful, 122286d8edStholo but WITHOUT ANY WARRANTY; without even the implied warranty of 132286d8edStholo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 142286d8edStholo GNU General Public License for more details. 152286d8edStholo 16c71bc7e2Stholo */ 172286d8edStholo 182286d8edStholo /* We must define `volatile' and `const' first (the latter inside config.h), 192286d8edStholo so that they're used consistently in all system includes. */ 202286d8edStholo #if !__STDC__ 212286d8edStholo #ifndef volatile 222286d8edStholo #define volatile 232286d8edStholo #endif 242286d8edStholo #endif 252286d8edStholo #include <config.h> 262286d8edStholo 272286d8edStholo #include <sys/types.h> 282286d8edStholo #include <sys/stat.h> 292286d8edStholo 30c71bc7e2Stholo /* Note that PARAMS is just internal to the diff library; diffrun.h 31c71bc7e2Stholo has its own mechanism, which will hopefully be less likely to 32c71bc7e2Stholo conflict with the library's caller's namespace. */ 332286d8edStholo #if __STDC__ 342286d8edStholo #define PARAMS(args) args 352286d8edStholo #define VOID void 362286d8edStholo #else 372286d8edStholo #define PARAMS(args) () 382286d8edStholo #define VOID char 392286d8edStholo #endif 402286d8edStholo 412286d8edStholo #if STAT_MACROS_BROKEN 422286d8edStholo #undef S_ISBLK 432286d8edStholo #undef S_ISCHR 442286d8edStholo #undef S_ISDIR 452286d8edStholo #undef S_ISFIFO 462286d8edStholo #undef S_ISREG 472286d8edStholo #undef S_ISSOCK 482286d8edStholo #endif 492286d8edStholo #ifndef S_ISDIR 502286d8edStholo #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 512286d8edStholo #endif 522286d8edStholo #ifndef S_ISREG 532286d8edStholo #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 542286d8edStholo #endif 552286d8edStholo #if !defined(S_ISBLK) && defined(S_IFBLK) 562286d8edStholo #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 572286d8edStholo #endif 582286d8edStholo #if !defined(S_ISCHR) && defined(S_IFCHR) 592286d8edStholo #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 602286d8edStholo #endif 612286d8edStholo #if !defined(S_ISFIFO) && defined(S_IFFIFO) 622286d8edStholo #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO) 632286d8edStholo #endif 642286d8edStholo #if !defined(S_ISSOCK) && defined(S_IFSOCK) 652286d8edStholo #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) 662286d8edStholo #endif 672286d8edStholo 682286d8edStholo #if HAVE_UNISTD_H 692286d8edStholo #include <unistd.h> 702286d8edStholo #endif 712286d8edStholo 722286d8edStholo #ifndef SEEK_SET 732286d8edStholo #define SEEK_SET 0 742286d8edStholo #endif 752286d8edStholo #ifndef SEEK_CUR 762286d8edStholo #define SEEK_CUR 1 772286d8edStholo #endif 782286d8edStholo 792286d8edStholo #ifndef STDIN_FILENO 802286d8edStholo #define STDIN_FILENO 0 812286d8edStholo #endif 822286d8edStholo #ifndef STDOUT_FILENO 832286d8edStholo #define STDOUT_FILENO 1 842286d8edStholo #endif 852286d8edStholo #ifndef STDERR_FILENO 862286d8edStholo #define STDERR_FILENO 2 872286d8edStholo #endif 882286d8edStholo 892286d8edStholo /* I believe that all relevant systems have 902286d8edStholo time.h. It is in ANSI, for example. The 912286d8edStholo code below looks quite bogus as I don't think 922286d8edStholo sys/time.h is ever a substitute for time.h; 932286d8edStholo it is something different. */ 942286d8edStholo #define HAVE_TIME_H 1 952286d8edStholo 962286d8edStholo #if HAVE_TIME_H 972286d8edStholo #include <time.h> 982286d8edStholo #else 992286d8edStholo #include <sys/time.h> 1002286d8edStholo #endif 1012286d8edStholo 1022286d8edStholo #if HAVE_FCNTL_H 1032286d8edStholo #include <fcntl.h> 1042286d8edStholo #else 1052286d8edStholo #if HAVE_SYS_FILE_H 1062286d8edStholo #include <sys/file.h> 1072286d8edStholo #endif 1082286d8edStholo #endif 1092286d8edStholo 1102286d8edStholo #ifndef O_RDONLY 1112286d8edStholo #define O_RDONLY 0 1122286d8edStholo #endif 1132286d8edStholo 1142286d8edStholo #if HAVE_SYS_WAIT_H 1152286d8edStholo #include <sys/wait.h> 1162286d8edStholo #endif 1172286d8edStholo #ifndef WEXITSTATUS 1182286d8edStholo #define WEXITSTATUS(stat_val) ((unsigned) (stat_val) >> 8) 1192286d8edStholo #endif 1202286d8edStholo #ifndef WIFEXITED 1212286d8edStholo #define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 1222286d8edStholo #endif 1232286d8edStholo 1242286d8edStholo #ifndef STAT_BLOCKSIZE 1252286d8edStholo #if HAVE_ST_BLKSIZE 1262286d8edStholo #define STAT_BLOCKSIZE(s) (s).st_blksize 1272286d8edStholo #else 1282286d8edStholo #define STAT_BLOCKSIZE(s) (8 * 1024) 1292286d8edStholo #endif 1302286d8edStholo #endif 1312286d8edStholo 1322286d8edStholo #if HAVE_DIRENT_H 1332286d8edStholo # include <dirent.h> 1342286d8edStholo # define NAMLEN(dirent) strlen((dirent)->d_name) 1352286d8edStholo #else 1362286d8edStholo # define dirent direct 1372286d8edStholo # define NAMLEN(dirent) ((dirent)->d_namlen) 1382286d8edStholo # if HAVE_SYS_NDIR_H 1392286d8edStholo # include <sys/ndir.h> 1402286d8edStholo # endif 1412286d8edStholo # if HAVE_SYS_DIR_H 1422286d8edStholo # include <sys/dir.h> 1432286d8edStholo # endif 1442286d8edStholo # if HAVE_NDIR_H 1452286d8edStholo # include <ndir.h> 1462286d8edStholo # endif 1472286d8edStholo #endif 1482286d8edStholo 1492286d8edStholo #if HAVE_VFORK_H 1502286d8edStholo #include <vfork.h> 1512286d8edStholo #endif 1522286d8edStholo 1532286d8edStholo #if HAVE_STDLIB_H || defined(STDC_HEADERS) 1542286d8edStholo #include <stdlib.h> 1552286d8edStholo #else 1562286d8edStholo VOID *malloc (); 1572286d8edStholo VOID *realloc (); 1582286d8edStholo #endif 1592286d8edStholo #ifndef getenv 1602286d8edStholo char *getenv (); 1612286d8edStholo #endif 1622286d8edStholo 1632286d8edStholo #if HAVE_LIMITS_H 1642286d8edStholo #include <limits.h> 1652286d8edStholo #endif 1662286d8edStholo #ifndef INT_MAX 1672286d8edStholo #define INT_MAX 2147483647 1682286d8edStholo #endif 1692286d8edStholo #ifndef CHAR_BIT 1702286d8edStholo #define CHAR_BIT 8 1712286d8edStholo #endif 1722286d8edStholo 1732286d8edStholo #if STDC_HEADERS || HAVE_STRING_H 1742286d8edStholo # include <string.h> 1752286d8edStholo # ifndef bzero 1762286d8edStholo # define bzero(s, n) memset (s, 0, n) 1772286d8edStholo # endif 1782286d8edStholo #else 1792286d8edStholo # if !HAVE_STRCHR 1802286d8edStholo # define strchr index 1812286d8edStholo # define strrchr rindex 1822286d8edStholo # endif 1832286d8edStholo char *strchr (), *strrchr (); 1842286d8edStholo # if !HAVE_MEMCHR 1852286d8edStholo # define memcmp(s1, s2, n) bcmp (s1, s2, n) 1862286d8edStholo # define memcpy(d, s, n) bcopy (s, d, n) 1872286d8edStholo void *memchr (); 1882286d8edStholo # endif 1892286d8edStholo #endif 1902286d8edStholo 1912286d8edStholo #include <ctype.h> 1922286d8edStholo /* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given 1932286d8edStholo as an argument to <ctype.h> macros like `isspace'. */ 1942286d8edStholo #if STDC_HEADERS 1952286d8edStholo #define CTYPE_DOMAIN(c) 1 1962286d8edStholo #else 1972286d8edStholo #define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177) 1982286d8edStholo #endif 1992286d8edStholo #ifndef ISPRINT 2002286d8edStholo #define ISPRINT(c) (CTYPE_DOMAIN (c) && isprint (c)) 2012286d8edStholo #endif 2022286d8edStholo #ifndef ISSPACE 2032286d8edStholo #define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c)) 2042286d8edStholo #endif 2052286d8edStholo #ifndef ISUPPER 2062286d8edStholo #define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c)) 2072286d8edStholo #endif 2082286d8edStholo 2092286d8edStholo #ifndef ISDIGIT 2102286d8edStholo #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) 2112286d8edStholo #endif 2122286d8edStholo 2132286d8edStholo #include <errno.h> 2142286d8edStholo #if !STDC_HEADERS 2152286d8edStholo extern int errno; 2162286d8edStholo #endif 2172286d8edStholo 2182286d8edStholo #ifdef min 2192286d8edStholo #undef min 2202286d8edStholo #endif 2212286d8edStholo #ifdef max 2222286d8edStholo #undef max 2232286d8edStholo #endif 2242286d8edStholo #define min(a,b) ((a) <= (b) ? (a) : (b)) 2252286d8edStholo #define max(a,b) ((a) >= (b) ? (a) : (b)) 2262286d8edStholo 2272286d8edStholo /* This section contains Posix-compliant defaults for macros 2282286d8edStholo that are meant to be overridden by hand in config.h as needed. */ 2292286d8edStholo 2302286d8edStholo #ifndef filename_cmp 2312286d8edStholo #define filename_cmp(a, b) strcmp (a, b) 2322286d8edStholo #endif 2332286d8edStholo 2342286d8edStholo #ifndef filename_lastdirchar 2352286d8edStholo #define filename_lastdirchar(filename) strrchr (filename, '/') 2362286d8edStholo #endif 2372286d8edStholo 2382286d8edStholo #ifndef HAVE_FORK 2392286d8edStholo #define HAVE_FORK 1 2402286d8edStholo #endif 2412286d8edStholo 2422286d8edStholo #ifndef HAVE_SETMODE 2432286d8edStholo #define HAVE_SETMODE 0 2442286d8edStholo #endif 2452286d8edStholo 2462286d8edStholo #ifndef initialize_main 2472286d8edStholo #define initialize_main(argcp, argvp) 2482286d8edStholo #endif 2492286d8edStholo 2502286d8edStholo /* Do struct stat *S, *T describe the same file? Answer -1 if unknown. */ 2512286d8edStholo #ifndef same_file 2522286d8edStholo #define same_file(s,t) ((s)->st_ino==(t)->st_ino && (s)->st_dev==(t)->st_dev) 2532286d8edStholo #endif 2542286d8edStholo 2552286d8edStholo /* Place into Q a quoted version of A suitable for `popen' or `system', 2562286d8edStholo incrementing Q and junking A. 2572286d8edStholo Do not increment Q by more than 4 * strlen (A) + 2. */ 2582286d8edStholo #ifndef SYSTEM_QUOTE_ARG 2592286d8edStholo #define SYSTEM_QUOTE_ARG(q, a) \ 2602286d8edStholo { \ 2612286d8edStholo *(q)++ = '\''; \ 2622286d8edStholo for (; *(a); *(q)++ = *(a)++) \ 2632286d8edStholo if (*(a) == '\'') \ 2642286d8edStholo { \ 2652286d8edStholo *(q)++ = '\''; \ 2662286d8edStholo *(q)++ = '\\'; \ 2672286d8edStholo *(q)++ = '\''; \ 2682286d8edStholo } \ 2692286d8edStholo *(q)++ = '\''; \ 2702286d8edStholo } 2712286d8edStholo #endif 272*43c1707eStholo 273*43c1707eStholo /* these come from CVS's lib/system.h, but I wasn't sure how to include that 274*43c1707eStholo * properly or even if I really should 275*43c1707eStholo */ 276*43c1707eStholo #ifndef CVS_OPENDIR 277*43c1707eStholo #define CVS_OPENDIR opendir 278*43c1707eStholo #endif 279*43c1707eStholo #ifndef CVS_READDIR 280*43c1707eStholo #define CVS_READDIR readdir 281*43c1707eStholo #endif 282*43c1707eStholo #ifndef CVS_CLOSEDIR 283*43c1707eStholo #define CVS_CLOSEDIR closedir 284*43c1707eStholo #endif 285