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