1 /* $NetBSD: system.h,v 1.1.1.1 2016/01/10 21:36:21 christos Exp $ */ 2 3 /* Portability cruft. Include after config.h and sys/types.h. 4 Copyright 1996, 1998, 1999, 2000 Free Software Foundation, Inc. 5 6 This program 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 This program 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 this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 02111-1307, USA. */ 20 21 #undef PARAMS 22 #if defined (__STDC__) && __STDC__ 23 # ifndef _PTR_T 24 # define _PTR_T 25 typedef void * ptr_t; 26 # endif 27 # define PARAMS(x) x 28 #else 29 # ifndef _PTR_T 30 # define _PTR_T 31 typedef char * ptr_t; 32 # endif 33 # define PARAMS(x) () 34 #endif 35 36 #ifdef HAVE_UNISTD_H 37 # include <fcntl.h> 38 # include <unistd.h> 39 #else 40 # define O_RDONLY 0 41 # define SEEK_SET 0 42 # define SEEK_CUR 1 43 int open(), read(), close(); 44 #endif 45 46 #include <errno.h> 47 #ifndef errno 48 extern int errno; 49 #endif 50 51 #ifndef HAVE_STRERROR 52 extern int sys_nerr; 53 extern char *sys_errlist[]; 54 # define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error")) 55 #endif 56 57 /* Some operating systems treat text and binary files differently. */ 58 #ifdef __BEOS__ 59 # undef O_BINARY /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ 60 #endif 61 #ifdef HAVE_DOS_FILE_CONTENTS 62 # include <io.h> 63 # ifdef HAVE_SETMODE 64 # define SET_BINARY(fd) setmode (fd, O_BINARY) 65 # else 66 # define SET_BINARY(fd) _setmode (fd, O_BINARY) 67 # endif 68 #endif 69 70 #ifdef HAVE_DOS_FILE_NAMES 71 # define IS_SLASH(c) ((c) == '/' || (c) == '\\') 72 # define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0) 73 #endif 74 75 #ifndef IS_SLASH 76 # define IS_SLASH(c) ((c) == '/') 77 #endif 78 79 #ifndef FILESYSTEM_PREFIX_LEN 80 # define FILESYSTEM_PREFIX_LEN(f) 0 81 #endif 82 83 int isdir PARAMS ((char const *)); 84 85 #ifdef HAVE_DIR_EACCES_BUG 86 # ifdef EISDIR 87 # define is_EISDIR(e, f) \ 88 ((e) == EISDIR \ 89 || ((e) == EACCES && isdir (f) && ((e) = EISDIR, 1))) 90 # else 91 # define is_EISDIR(e, f) ((e) == EACCES && isdir (f)) 92 # endif 93 #endif 94 95 #ifndef is_EISDIR 96 # ifdef EISDIR 97 # define is_EISDIR(e, f) ((e) == EISDIR) 98 # else 99 # define is_EISDIR(e, f) 0 100 # endif 101 #endif 102 103 #if STAT_MACROS_BROKEN 104 # undef S_ISDIR 105 # undef S_ISREG 106 #endif 107 #if !defined(S_ISDIR) && defined(S_IFDIR) 108 # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR) 109 #endif 110 #if !defined(S_ISREG) && defined(S_IFREG) 111 # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG) 112 #endif 113 114 #ifdef STDC_HEADERS 115 # include <stdlib.h> 116 #else 117 char *getenv (); 118 ptr_t malloc(), realloc(), calloc(); 119 void free(); 120 #endif 121 122 #if __STDC__ 123 # include <stddef.h> 124 #endif 125 #ifdef STDC_HEADERS 126 # include <limits.h> 127 #endif 128 #ifndef CHAR_BIT 129 # define CHAR_BIT 8 130 #endif 131 /* The extra casts work around common compiler bugs. */ 132 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) 133 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \ 134 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \ 135 : (t) 0)) 136 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t))) 137 #ifndef CHAR_MAX 138 # define CHAR_MAX TYPE_MAXIMUM (char) 139 #endif 140 #ifndef INT_MAX 141 # define INT_MAX TYPE_MAXIMUM (int) 142 #endif 143 #ifndef UCHAR_MAX 144 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char) 145 #endif 146 147 #if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H) 148 # include <memory.h> 149 #endif 150 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H) 151 # include <string.h> 152 #else 153 # include <strings.h> 154 # undef strchr 155 # define strchr index 156 # undef strrchr 157 # define strrchr rindex 158 # undef memcpy 159 # define memcpy(d, s, n) bcopy (s, d, n) 160 #endif 161 #ifndef HAVE_MEMCHR 162 ptr_t memchr(); 163 #endif 164 #if ! defined HAVE_MEMMOVE && ! defined memmove 165 # define memmove(d, s, n) bcopy (s, d, n) 166 #endif 167 168 #include <ctype.h> 169 170 #ifndef isgraph 171 # define isgraph(C) (isprint(C) && !isspace(C)) 172 #endif 173 174 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) 175 # define IN_CTYPE_DOMAIN(c) 1 176 #else 177 # define IN_CTYPE_DOMAIN(c) isascii(c) 178 #endif 179 180 #define ISALPHA(C) (IN_CTYPE_DOMAIN (C) && isalpha (C)) 181 #define ISUPPER(C) (IN_CTYPE_DOMAIN (C) && isupper (C)) 182 #define ISLOWER(C) (IN_CTYPE_DOMAIN (C) && islower (C)) 183 #define ISDIGIT(C) (IN_CTYPE_DOMAIN (C) && isdigit (C)) 184 #define ISXDIGIT(C) (IN_CTYPE_DOMAIN (C) && isxdigit (C)) 185 #define ISSPACE(C) (IN_CTYPE_DOMAIN (C) && isspace (C)) 186 #define ISPUNCT(C) (IN_CTYPE_DOMAIN (C) && ispunct (C)) 187 #define ISALNUM(C) (IN_CTYPE_DOMAIN (C) && isalnum (C)) 188 #define ISPRINT(C) (IN_CTYPE_DOMAIN (C) && isprint (C)) 189 #define ISGRAPH(C) (IN_CTYPE_DOMAIN (C) && isgraph (C)) 190 #define ISCNTRL(C) (IN_CTYPE_DOMAIN (C) && iscntrl (C)) 191 192 #define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C)) 193 194 #if ENABLE_NLS 195 # include <libintl.h> 196 # define _(String) gettext (String) 197 #else 198 # define _(String) String 199 #endif 200 #define N_(String) String 201 202 #if HAVE_SETLOCALE 203 # include <locale.h> 204 #endif 205 206 #ifndef initialize_main 207 #define initialize_main(argcp, argvp) 208 #endif 209