1/* $NetBSD$ */ 2 3/* -*- Mode: C -*- */ 4 5/** 6 * \file compat.h --- fake the preprocessor into handlng portability 7 * 8 * Time-stamp: "2010-07-16 15:11:57 bkorb" 9 * 10 * compat.h is free software. 11 * This file is part of AutoGen. 12 * 13 * AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved 14 * 15 * AutoGen is free software: you can redistribute it and/or modify it 16 * under the terms of the GNU General Public License as published by the 17 * Free Software Foundation, either version 3 of the License, or 18 * (at your option) any later version. 19 * 20 * AutoGen is distributed in the hope that it will be useful, but 21 * WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 * See the GNU General Public License for more details. 24 * 25 * You should have received a copy of the GNU General Public License along 26 * with this program. If not, see <http://www.gnu.org/licenses/>. 27 * 28 * As a special exception, Bruce Korb gives permission for additional 29 * uses of the text contained in the release of compat.h. 30 * 31 * The exception is that, if you link the compat.h library with other 32 * files to produce an executable, this does not by itself cause the 33 * resulting executable to be covered by the GNU General Public License. 34 * Your use of that executable is in no way restricted on account of 35 * linking the compat.h library code into it. 36 * 37 * This exception does not however invalidate any other reasons why 38 * the executable file might be covered by the GNU General Public License. 39 * 40 * This exception applies only to the code released by Bruce Korb under 41 * the name compat.h. If you copy code from other sources under the 42 * General Public License into a copy of compat.h, as the General Public 43 * License permits, the exception does not apply to the code that you add 44 * in this way. To avoid misleading anyone as to the status of such 45 * modified files, you must delete this exception notice from them. 46 * 47 * If you write modifications of your own for compat.h, it is your choice 48 * whether to permit this exception to apply to your modifications. 49 * If you do not wish that, delete this exception notice. 50 */ 51#ifndef COMPAT_H_GUARD 52#define COMPAT_H_GUARD 1 53 54#if defined(HAVE_CONFIG_H) 55# include <config.h> 56 57#elif defined(_WIN32) && !defined(__CYGWIN__) 58# include "windows-config.h" 59 60#else 61# error "compat.h" requires "config.h" 62 choke me. 63#endif 64 65 66#ifndef HAVE_STRSIGNAL 67 char * strsignal( int signo ); 68#endif 69 70#define _GNU_SOURCE 1 /* for strsignal in GNU's libc */ 71#define __USE_GNU 1 /* exact same thing as above */ 72#define __EXTENSIONS__ 1 /* and another way to call for it */ 73 74/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 75 * 76 * SYSTEM HEADERS: 77 */ 78#include <sys/types.h> 79#ifdef HAVE_SYS_MMAN_H 80# include <sys/mman.h> 81#endif 82#include <sys/param.h> 83#if HAVE_SYS_PROCSET_H 84# include <sys/procset.h> 85#endif 86#include <sys/stat.h> 87#include <sys/wait.h> 88 89#if defined( HAVE_SOLARIS_SYSINFO ) 90# include <sys/systeminfo.h> 91#elif defined( HAVE_UNAME_SYSCALL ) 92# include <sys/utsname.h> 93#endif 94 95#ifdef DAEMON_ENABLED 96# if HAVE_SYS_STROPTS_H 97# include <sys/stropts.h> 98# endif 99 100# if HAVE_SYS_SOCKET_H 101# include <sys/socket.h> 102# endif 103 104# if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H) 105# error This system cannot support daemon processing 106 Choke Me. 107# endif 108 109# if HAVE_SYS_POLL_H 110# include <sys/poll.h> 111# endif 112 113# if HAVE_SYS_SELECT_H 114# include <sys/select.h> 115# endif 116 117# if HAVE_NETINET_IN_H 118# include <netinet/in.h> 119# endif 120 121# if HAVE_SYS_UN_H 122# include <sys/un.h> 123# endif 124#endif 125 126/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 127 * 128 * USER HEADERS: 129 */ 130#include <stdio.h> 131#include <assert.h> 132#include <ctype.h> 133 134/* 135 * Directory opening stuff: 136 */ 137# if defined (_POSIX_SOURCE) 138/* Posix does not require that the d_ino field be present, and some 139 systems do not provide it. */ 140# define REAL_DIR_ENTRY(dp) 1 141# else /* !_POSIX_SOURCE */ 142# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) 143# endif /* !_POSIX_SOURCE */ 144 145# if defined (HAVE_DIRENT_H) 146# include <dirent.h> 147# define D_NAMLEN(dirent) strlen((dirent)->d_name) 148# else /* !HAVE_DIRENT_H */ 149# define dirent direct 150# define D_NAMLEN(dirent) (dirent)->d_namlen 151# if defined (HAVE_SYS_NDIR_H) 152# include <sys/ndir.h> 153# endif /* HAVE_SYS_NDIR_H */ 154# if defined (HAVE_SYS_DIR_H) 155# include <sys/dir.h> 156# endif /* HAVE_SYS_DIR_H */ 157# if defined (HAVE_NDIR_H) 158# include <ndir.h> 159# endif /* HAVE_NDIR_H */ 160# endif /* !HAVE_DIRENT_H */ 161 162#include <errno.h> 163#ifdef HAVE_FCNTL_H 164# include <fcntl.h> 165#endif 166#ifndef O_NONBLOCK 167# define O_NONBLOCK FNDELAY 168#endif 169 170#if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H) 171# include <libgen.h> 172#endif 173 174#if defined(HAVE_LIMITS_H) /* this is also in options.h */ 175# include <limits.h> 176#elif defined(HAVE_SYS_LIMITS_H) 177# include <sys/limits.h> 178#endif /* HAVE_LIMITS/SYS_LIMITS_H */ 179 180#include <memory.h> 181#include <setjmp.h> 182#include <signal.h> 183 184#if defined( HAVE_STDINT_H ) 185# include <stdint.h> 186#elif defined( HAVE_INTTYPES_H ) 187# include <inttypes.h> 188#endif 189 190#include <stdlib.h> 191#include <string.h> 192 193#include <time.h> 194 195#ifdef HAVE_UTIME_H 196# include <utime.h> 197#endif 198 199#ifdef HAVE_UNISTD_H 200# include <unistd.h> 201#endif 202 203/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 204 * 205 * FIXUPS and CONVIENCE STUFF: 206 */ 207#ifdef __cplusplus 208# define EXTERN extern "C" 209#else 210# define EXTERN extern 211#endif 212 213/* some systems #def errno! and others do not declare it!! */ 214#ifndef errno 215 extern int errno; 216#endif 217 218/* Some machines forget this! */ 219 220# ifndef EXIT_FAILURE 221# define EXIT_SUCCESS 0 222# define EXIT_FAILURE 1 223# endif 224 225#ifndef NUL 226# define NUL '\0' 227#endif 228 229#ifndef NULL 230# define NULL 0 231#endif 232 233#if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H) 234# include <sys/param.h> 235#endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */ 236 237#if !defined (MAXPATHLEN) && defined (PATH_MAX) 238# define MAXPATHLEN PATH_MAX 239#endif /* !MAXPATHLEN && PATH_MAX */ 240 241#if !defined (MAXPATHLEN) && defined(_MAX_PATH) 242# define PATH_MAX _MAX_PATH 243# define MAXPATHLEN _MAX_PATH 244#endif 245 246#if !defined (MAXPATHLEN) 247# define MAXPATHLEN ((size_t)4096) 248#endif /* MAXPATHLEN */ 249 250#define AG_PATH_MAX ((size_t)MAXPATHLEN) 251 252#ifndef LONG_MAX 253# define LONG_MAX ~(1L << (8*sizeof(long) -1)) 254# define INT_MAX ~(1 << (8*sizeof(int) -1)) 255#endif 256 257#ifndef ULONG_MAX 258# define ULONG_MAX ~(OUL) 259# define UINT_MAX ~(OU) 260#endif 261 262#ifndef SHORT_MAX 263# define SHORT_MAX ~(1 << (8*sizeof(short) - 1)) 264#else 265# define USHORT_MAX ~(OUS) 266#endif 267 268#ifndef HAVE_INT8_T 269 typedef signed char int8_t; 270# define HAVE_INT8_T 1 271#endif 272#ifndef HAVE_UINT8_T 273 typedef unsigned char uint8_t; 274# define HAVE_UINT8_T 1 275#endif 276#ifndef HAVE_INT16_T 277 typedef signed short int16_t; 278# define HAVE_INT16_T 1 279#endif 280#ifndef HAVE_UINT16_T 281 typedef unsigned short uint16_t; 282# define HAVE_UINT16_T 1 283#endif 284 285#ifndef HAVE_INT32_T 286# if SIZEOF_INT == 4 287 typedef signed int int32_t; 288# elif SIZEOF_LONG == 4 289 typedef signed long int32_t; 290# endif 291# define HAVE_INT32_T 1 292#endif 293 294#ifndef HAVE_UINT32_T 295# if SIZEOF_INT == 4 296 typedef unsigned int uint32_t; 297# elif SIZEOF_LONG == 4 298 typedef unsigned long uint32_t; 299# else 300# error Cannot create a uint32_t type. 301 Choke Me. 302# endif 303# define HAVE_UINT32_T 1 304#endif 305 306#ifndef HAVE_INTPTR_T 307# if SIZEOF_CHARP == SIZEOF_LONG 308 typedef signed long intptr_t; 309# else 310 typedef signed int intptr_t; 311# endif 312# define HAVE_INTPTR_T 1 313#endif 314 315#ifndef HAVE_UINTPTR_T 316# if SIZEOF_CHARP == SIZEOF_LONG 317 typedef unsigned long intptr_t; 318# else 319 typedef unsigned int intptr_t; 320# endif 321# define HAVE_INTPTR_T 1 322#endif 323 324#ifndef HAVE_UINT_T 325 typedef unsigned int uint_t; 326# define HAVE_UINT_T 1 327#endif 328 329#ifndef HAVE_SIZE_T 330 typedef unsigned int size_t; 331# define HAVE_SIZE_T 1 332#endif 333#ifndef HAVE_WINT_T 334 typedef unsigned int wint_t; 335# define HAVE_WINT_T 1 336#endif 337#ifndef HAVE_PID_T 338 typedef signed int pid_t; 339# define HAVE_PID_T 1 340#endif 341 342/* redefine these for BSD style string libraries */ 343#ifndef HAVE_STRCHR 344# define strchr index 345# define strrchr rindex 346#endif 347 348#ifdef USE_FOPEN_BINARY 349# ifndef FOPEN_BINARY_FLAG 350# define FOPEN_BINARY_FLAG "b" 351# endif 352# ifndef FOPEN_TEXT_FLAG 353# define FOPEN_TEXT_FLAG "t" 354# endif 355#else 356# ifndef FOPEN_BINARY_FLAG 357# define FOPEN_BINARY_FLAG 358# endif 359# ifndef FOPEN_TEXT_FLAG 360# define FOPEN_TEXT_FLAG 361# endif 362#endif 363 364#ifndef STR 365# define _STR(s) #s 366# define STR(s) _STR(s) 367#endif 368 369/* ##### Pointer sized word ##### */ 370 371/* FIXME: the MAX stuff in here is broken! */ 372#if SIZEOF_CHARP > SIZEOF_INT 373 typedef long t_word; 374 #define WORD_MAX LONG_MAX 375 #define WORD_MIN LONG_MIN 376#else /* SIZEOF_CHARP <= SIZEOF_INT */ 377 typedef int t_word; 378 #define WORD_MAX INT_MAX 379 #define WORD_MIN INT_MIN 380#endif 381 382#endif /* COMPAT_H_GUARD */ 383 384/* 385 * Local Variables: 386 * mode: C 387 * c-file-style: "stroustrup" 388 * indent-tabs-mode: nil 389 * End: 390 * end of compat/compat.h */ 391