1/* Dirty system-dependent hacks. 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 3 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 4 5This file is part of GNU Wget. 6 7GNU Wget is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 3 of the License, or (at 10your option) any later version. 11 12GNU Wget is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with Wget. If not, see <http://www.gnu.org/licenses/>. 19 20Additional permission under GNU GPL version 3 section 7 21 22If you modify this program, or any covered work, by linking or 23combining it with the OpenSSL project's OpenSSL library (or a 24modified version of that library), containing parts covered by the 25terms of the OpenSSL or SSLeay licenses, the Free Software Foundation 26grants you additional permission to convey the resulting work. 27Corresponding Source for a non-source form of such a combination 28shall include the source code for the parts of OpenSSL used as well 29as that of the covered work. */ 30 31/* This file is included by wget.h. Random .c files need not include 32 it. */ 33 34#ifndef SYSDEP_H 35#define SYSDEP_H 36 37/* Testing for __sun is not enough because it's also defined on SunOS. */ 38#ifdef __sun 39# ifdef __SVR4 40# define solaris 41# endif 42#endif 43 44#if defined(__INTERIX) && !defined(_ALL_SOURCE) 45# define _ALL_SOURCE 46#endif 47 48/* The "namespace tweaks" below attempt to set a friendly "compilation 49 environment" under popular operating systems. Default compilation 50 environment often means that some functions that are "extensions" 51 are not declared -- `strptime' is one example. 52 53 But non-default environments can expose bugs in the system header 54 files, crippling compilation in _very_ non-obvious ways. Because 55 of that, we define them only on well-tested architectures where we 56 know they will work. */ 57 58#undef NAMESPACE_TWEAKS 59 60#ifdef solaris 61# define NAMESPACE_TWEAKS 62#endif 63 64#if defined(__linux__) || defined(__GLIBC__) 65# define NAMESPACE_TWEAKS 66#endif 67 68#ifdef NAMESPACE_TWEAKS 69 70/* Request the "Unix 98 compilation environment". */ 71#define _XOPEN_SOURCE 500 72 73/* For Solaris: request everything else that is available and doesn't 74 conflict with the above. */ 75/* #define __EXTENSIONS__ */ /* XXX clashes with config.h */ 76 77/* For Linux: request features of 4.3BSD and SVID (System V Interface 78 Definition). */ 79#define _SVID_SOURCE 80#define _BSD_SOURCE 81 82/* Under glibc-based systems we want all GNU extensions as well. This 83 declares some unnecessary cruft, but also useful functions such as 84 timegm, FNM_CASEFOLD extension to fnmatch, memrchr, etc. */ 85/* #define _GNU_SOURCE */ /* XXX clashes with config.h */ 86 87#endif /* NAMESPACE_TWEAKS */ 88 89 90/* Alloca declaration, based on recommendation in the Autoconf manual. 91 These have to be after the above namespace tweaks, but before any 92 non-preprocessor code. */ 93 94#if HAVE_ALLOCA_H 95# include <alloca.h> 96#elif defined WINDOWS 97# include <malloc.h> 98# ifndef alloca 99# define alloca _alloca 100# endif 101#elif defined __GNUC__ 102# define alloca __builtin_alloca 103#elif defined _AIX 104# define alloca __alloca 105#else 106# include <stddef.h> 107# ifdef __cplusplus 108extern "C" 109# endif 110void *alloca (size_t); 111#endif 112 113/* Must include these, so we can test for the missing stat macros and 114 define them as necessary. */ 115#include <sys/types.h> 116#include <sys/stat.h> 117 118#ifdef HAVE_INTTYPES_H 119 /* Compaq C V6.5-303 (dtk) on HP Tru64 UNIX V5.1B (Rev. 2650) needs: */ 120# include <stdint.h> 121# include <inttypes.h> 122#endif 123 124#ifdef WINDOWS 125/* Windows doesn't have some functions normally found on Unix-like 126 systems, such as strcasecmp, strptime, etc. Include mswindows.h so 127 we get the declarations for their replacements in mswindows.c, as 128 well as to pick up Windows-specific includes and constants. To be 129 able to test for such features, the file must be included as early 130 as possible. */ 131# include "mswindows.h" 132#endif 133 134/* Provide support for C99-type boolean type "bool". This blurb comes 135 straight from the Autoconf 2.59 manual. */ 136#if HAVE_STDBOOL_H 137# include <stdbool.h> 138#else 139# if ! HAVE__BOOL 140# ifdef __cplusplus 141typedef bool _Bool; 142# else 143typedef unsigned char _Bool; 144# endif 145# endif 146# define bool _Bool 147# define false 0 148# define true 1 149# define __bool_true_false_are_defined 1 150#endif 151 152/* Needed for compilation under OS/2 and MSDOS */ 153#if defined(__EMX__) || defined(MSDOS) 154# ifndef S_ISLNK 155# define S_ISLNK(m) 0 156# endif 157# ifndef lstat 158# define lstat stat 159# endif 160#endif /* __EMX__ || MSDOS */ 161 162/* Reportedly, stat() macros are broken on some old systems. Those 163 systems will have to fend for themselves, as I will not introduce 164 new code to handle it. 165 166 However, I will add code for *missing* macros, and the following 167 are reportedly missing from many systems. */ 168#ifndef S_ISLNK 169# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 170#endif 171#ifndef S_ISDIR 172# define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR)) 173#endif 174#ifndef S_ISREG 175# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) 176#endif 177 178/* These are needed so we can #define struct_stat to struct _stati64 179 under Windows. */ 180#ifndef struct_stat 181# define struct_stat struct stat 182#endif 183#ifndef struct_fstat 184# define struct_fstat struct stat 185#endif 186 187/* For CHAR_BIT, LONG_MAX, etc. */ 188#include <limits.h> 189 190#ifndef CHAR_BIT 191# define CHAR_BIT 8 192#endif 193 194/* From gnulib, simplified to assume a signed type. */ 195#define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) 196 197/* These are defined in cmpt.c if missing, so we must declare 198 them. */ 199#ifndef HAVE_STRCASECMP 200int strcasecmp (); 201#endif 202#ifndef HAVE_STRNCASECMP 203int strncasecmp (); 204#endif 205#ifndef HAVE_STRPTIME 206char *strptime (); 207#endif 208#ifndef HAVE_TIMEGM 209# include <time.h> 210time_t timegm (struct tm *); 211#endif 212#ifndef HAVE_MEMRCHR 213void *memrchr (const void *, int, size_t); 214#endif 215 216/* These are defined in snprintf.c. It would be nice to have an 217 snprintf.h, though. */ 218#ifndef HAVE_SNPRINTF 219int snprintf (); 220#endif 221#ifndef HAVE_VSNPRINTF 222int vsnprintf (); 223#endif 224 225/* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't 226 provide MAP_FAILED, a symbolic constant for the value returned by 227 mmap() when it doesn't work. Usually, this constant should be -1. 228 This only makes sense for files that use mmap() and include 229 sys/mman.h *before* sysdep.h, but doesn't hurt others. */ 230 231#ifndef MAP_FAILED 232# define MAP_FAILED ((void *) -1) 233#endif 234 235/* Enable system fnmatch only on systems where fnmatch.h is usable. 236 If the fnmatch on your system is buggy, undef this symbol and a 237 replacement implementation will be used instead. */ 238#ifdef HAVE_WORKING_FNMATCH_H 239# define SYSTEM_FNMATCH 240#endif 241 242#ifdef SYSTEM_FNMATCH 243# include <fnmatch.h> 244#else /* not SYSTEM_FNMATCH */ 245/* Define fnmatch flags. Undef them first to avoid warnings in case 246 an evil library include chose to include system fnmatch.h. */ 247# undef FNM_PATHNAME 248# undef FNM_NOESCAPE 249# undef FNM_PERIOD 250# undef FNM_NOMATCH 251 252# define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */ 253# define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */ 254# define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */ 255# define FNM_NOMATCH 1 256 257int fnmatch (const char *, const char *, int); 258#endif 259 260/* Provide sig_atomic_t if the system doesn't. */ 261#ifndef HAVE_SIG_ATOMIC_T 262typedef int sig_atomic_t; 263#endif 264 265/* Provide uint32_t on the platforms that don't define it. Although 266 most code should be agnostic about integer sizes, some code really 267 does need a 32-bit integral type. Such code should use uint32_t. 268 (The exception is gnu-md5.[ch], which uses its own detection for 269 portability across platforms.) */ 270 271#ifndef HAVE_UINT32_T 272# if SIZEOF_INT == 4 273typedef unsigned int uint32_t; 274# else 275# if SIZEOF_LONG == 4 276typedef unsigned long uint32_t; 277# else 278# if SIZEOF_SHORT == 4 279typedef unsigned short uint32_t; 280# else 281 #error "Cannot determine a 32-bit unsigned integer type" 282# endif 283# endif 284# endif 285#endif 286 287/* If uintptr_t isn't defined, simply typedef it to unsigned long. */ 288#ifndef HAVE_UINTPTR_T 289typedef unsigned long uintptr_t; 290#endif 291 292/* If intptr_t isn't defined, simply typedef it to long. */ 293#ifndef HAVE_INTPTR_T 294typedef long intptr_t; 295#endif 296 297#endif /* SYSDEP_H */ 298