1 /************************************************************************** 2 NETPBM 3 pm_config.in.h 4 *************************************************************************** 5 This file provides platform-dependent definitions for all Netpbm 6 libraries and the programs that use them. 7 8 The make files generate pm_config.h by copying this file and adding 9 other stuff. The Netpbm programs #include pm_config.h. 10 11 Wherever possible, Netpbm handles customization via the make files 12 instead of via this file. However, Netpbm's make file philosophy 13 discourages lining up a bunch of -D options on every compile, so a 14 #define here would be preferable to a -D compile option. 15 16 **************************************************************************/ 17 18 #if defined(USG) || defined(SVR4) || defined(__SVR4) 19 #define SYSV 20 #endif 21 #if !( defined(BSD) || defined(SYSV) || defined(MSDOS) || defined(__amigaos__)) 22 /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a 23 ** System V site, set the SYSV option; if you're IBM-compatible, set MSDOS; 24 ** and if you run on an Amiga, set AMIGA. If your compiler is ANSI C, you're 25 ** probably better off setting SYSV - all it affects is string handling. 26 */ 27 #define BSD 28 /* #define SYSV */ 29 /* #define MSDOS */ 30 #endif 31 32 /* Switch macros like _POSIX_SOURCE are supposed to add features from 33 the indicated standard to the C library. A source file defines one 34 of these macros to declare that it uses features of that standard 35 as opposed to conflicting features of other standards (e.g. the 36 POSIX foo() subroutine might do something different from the X/Open 37 foo() subroutine). Plus, this forces the coder to understand upon 38 what feature sets his program relies. 39 40 But some C library developers have misunderstood this and think of these 41 macros like the old __ansi__ macro, which tells the C library, "Don't 42 have any features that aren't in the ANSI standard." I.e. it's just 43 the opposite -- the macro subtracts features instead of adding them. 44 45 This means that on some platforms, Netpbm programs must define 46 _POSIX_SOURCE, and on others, it must not. Netpbm's POSIX_IS_IMPLIED 47 macro indicates that we're on a platform where we need not define 48 _POSIX_SOURCE (and probably must not). 49 50 The problematic C libraries treat _XOPEN_SOURCE the same way. 51 */ 52 #if defined(__OpenBSD__) || defined (__NetBSD__) || defined(__bsdi__) || defined(__APPLE__) 53 #define POSIX_IS_IMPLIED 54 #endif 55 56 57 /* CONFIGURE: This is the name of an environment variable that tells 58 ** where the color names database is. If the environment variable isn't 59 ** set, Netpbm tries the hardcoded defaults per macro 'RGB_DB_PATH' 60 ** (see below). 61 */ 62 #define RGBENV "RGBDEF" /* name of env-var */ 63 64 /* CONFIGURE: There should be an environment variable telling where the color 65 ** names database (color dictionary) is for Netpbm to use, e.g. to determine 66 ** what color "Salmon" is. The name of that environment variable is 67 ** above. But as some people prefer hardcoded file paths to environment 68 ** variables, if such environment variable is not set, Netpbm looks for the 69 ** first existing file in the list which is the value of 'RGB_DB_PATH'. And 70 ** if none of those exist (including if the list is empty), Netpbm simply 71 ** doesn't understand any color names. Note that Netpbm comes with a color 72 ** database (lib/rgb.txt in the source tree), but you might choose to have 73 ** Netpbm use a different one. See the documentation of ppm_parsecolor() 74 ** for the format of the color database file. 75 */ 76 77 #if (defined(SYSV) || defined(__amigaos__)) 78 79 #include <string.h> 80 81 #ifndef __SASC 82 #ifndef _DCC /* Amiga DICE Compiler */ 83 #define bzero(dst,len) memset(dst,0,len) 84 #define bcopy(src,dst,len) memcpy(dst,src,len) 85 #define bcmp memcmp 86 #endif /* _DCC */ 87 #endif /* __SASC */ 88 89 #endif /*SYSV or Amiga*/ 90 91 /* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on 92 ** system V, it gets declared in malloc.h. On some systems, malloc.h 93 ** doesn't declare these, so we have to do it here. On other systems, 94 ** for example HP/UX, it declares them incompatibly. And some systems, 95 ** for example Dynix, don't have a malloc.h at all. A sad situation. 96 ** If you have compilation problems that point here, feel free to tweak 97 ** or remove these declarations. 98 */ 99 #ifdef BSD 100 #include <stdlib.h> 101 #endif 102 #if defined(SYSV) 103 #include <malloc.h> 104 #endif 105 106 /* MSVCRT means we're using the Microsoft Visual C++ runtime library. 107 108 _WIN32, set by the compiler, apparently means the same thing; we see it set 109 in compiles using the Microsoft Visual C++ development environment and also 110 with Mingw, which is the Windows version of the GNU compiler (which brings 111 with it a runtime library which wraps around the Microsoft one). We don't 112 see it set in Cygwin compiles, which use GNU libraries instead of the 113 Microsoft one. 114 115 There is also _MSC_VER, which is set by MSVC to the version number of the 116 MSVC runtime library and __MINGW32__. 117 */ 118 119 #ifdef _WIN32 120 #define MSVCRT 1 121 #else 122 #define MSVCRT 0 123 #endif 124 125 /* WIN32 is a macro that some older compilers predefine (compilers aren't 126 supposed to because it doesn't start with an underscore, hence the change). 127 Many build systems (project files, etc.) set WIN32 explicitly for 128 backward compatibility. Netpbm doesn't use it. 129 */ 130 131 /* CONFIGURE: If your system has the setmode() function, set HAVE_SETMODE. 132 ** If you do, and also the O_BINARY file mode, pm_init() will set the mode 133 ** of stdin and stdout to binary for all Netpbm programs. 134 ** You need this with Cygwin (Windows). 135 */ 136 #if MSVCRT || defined(__CYGWIN__) || defined(DJGPP) 137 #define HAVE_SETMODE 138 #endif 139 140 #if MSVCRT || defined(__CYGWIN__) || defined(DJGPP) 141 #define HAVE_IO_H 1 142 #else 143 #define HAVE_IO_H 0 144 #endif 145 146 #if (defined(__GLIBC__) || defined(__GNU_LIBRARY__) || defined(__APPLE__)) || defined(__NetBSD__) 147 #define HAVE_VASPRINTF 1 148 #else 149 #define HAVE_VASPRINTF 0 150 #endif 151 152 /* On Windows, unlinking a file is deleting it, and you can't delete an open 153 file, so unlink of an open file fails. The errno is (incorrectly) EACCES. 154 */ 155 #if MSVCRT || defined(__CYGWIN__) || defined(DJGPP) 156 #define CAN_UNLINK_OPEN 0 157 #else 158 #define CAN_UNLINK_OPEN 1 159 #endif 160 161 #ifdef __amigaos__ 162 #include <clib/exec_protos.h> 163 #define getpid() ((pid_t)FindTask(NULL)) 164 #endif 165 166 #ifdef DJGPP 167 #define lstat stat 168 #endif 169 170 /* CONFIGURE: Netpbm uses __inline__ to declare functions that should 171 be compiled as inline code. GNU C recognizes the __inline__ keyword. 172 If your compiler recognizes any other keyword for this, you can set 173 it here. 174 */ 175 #if !defined(__GNUC__) 176 #if (!defined(__inline__)) 177 #if (defined(__sgi) || defined(_AIX)) 178 #define __inline__ __inline 179 #else 180 #define __inline__ 181 #endif 182 #endif 183 #endif 184 185 /* At least one compiler can't handle two declarations of the same function 186 that aren't literally identical. E.g. "static foo_fn_t foo1;" conflicts 187 with "static void foo1(int);" even if type 'foo_fn_t' is defined as 188 void(int). (The compiler we saw do this is SGI IDO cc (for IRIX 4.3)). 189 190 LITERAL_FN_DEF_MATCH says that the compiler might have this problem, 191 so one must be conservative in redeclaring functions. 192 */ 193 #if defined(__GNUC__) 194 #define LITERAL_FN_DEF_MATCH 0 195 #else 196 #if (defined(__sgi)) 197 #define LITERAL_FN_DEF_MATCH 1 198 #else 199 #define LITERAL_FN_DEF_MATCH 0 200 #endif 201 #endif 202 203 /* CONFIGURE: GNU Compiler extensions are used in performance critical places 204 when available. Test whether they exist. 205 206 Prevent the build from exploiting these extensions by defining 207 NO_GCC_UNIQUE. 208 209 Before Netpbm 10.65 (December 2013), Netpbm used GCC compiler extensions 210 to generate SSE code in Pamflip. Starting in 10.65, Netpbm instead uses 211 the more standard operators defined in <emmtrins.h>. To prevent Netpbm 212 from explicitly using any SSE instructions, set WANT_SSE to N in 213 config.mk. 214 */ 215 216 #if defined(__GNUC__) && !defined(NO_GCC_UNIQUE) 217 #define GCCVERSION __GNUC__*100 + __GNUC_MINOR__ 218 #else 219 #define GCCVERSION 0 220 #endif 221 222 #ifndef HAVE_GCC_BITCOUNT 223 #if GCCVERSION >=304 224 #define HAVE_GCC_BITCOUNT 1 225 /* Use __builtin_clz(), __builtin_ctz() (and variants for long) 226 to count leading/trailing 0s in int (and long). */ 227 #else 228 #define HAVE_GCC_BITCOUNT 0 229 #endif 230 #endif 231 232 #ifndef HAVE_GCC_BSWAP 233 #if GCCVERSION >=403 || defined(__clang__) 234 #define HAVE_GCC_BSWAP 1 235 /* Use __builtin_bswap32(), __builtin_bswap64() for endian conversion. 236 NOTE: On intel CPUs this may produce the bswap operand which is not 237 available on 80386. */ 238 #else 239 #define HAVE_GCC_BSWAP 0 240 #endif 241 #endif 242 243 #ifndef HAVE_WORKING_SSE2 244 #if defined(__SSE2__) && ( GCCVERSION >=402 || defined(__clang__) ) 245 #define HAVE_WORKING_SSE2 1 246 /* We can use SSE2 builtin functions to exploit SSE2 instructions. GCC 247 version 4.2 or newer is required; older GCC ostensibly has these SSE2 248 builtins, but the compiler aborts with an error. Note that __SSE2__ 249 means not only that the compiler has the capability, but that the user 250 has not disabled it via compiler options. 251 */ 252 #else 253 #define HAVE_WORKING_SSE2 0 254 #endif 255 #endif 256 257 /* UNALIGNED_OK means it's OK to do unaligned memory access, e.g. 258 loading an 8-byte word from an address that is not a multiple of 8. 259 On some systems, such an access causes a trap and a signal. 260 261 This determination is conservative - There may be cases where unaligned 262 access is OK and we say here it isn't. 263 264 We know unaligned access is _not_ OK on at least SPARC and some ARM. 265 */ 266 267 #if defined(__x86_64__) | defined(__i486__) | defined(__vax__) 268 # define UNALIGNED_OK 1 269 #else 270 # define UNALIGNED_OK 0 271 #endif 272 273 274 /* CONFIGURE: Some systems seem to need more than standard program linkage 275 to get a data (as opposed to function) item out of a library. 276 277 On Windows mingw systems, it seems you have to #include <import_mingw.h> 278 and #define EXTERNDATA DLL_IMPORT . 2001.05.19 279 */ 280 #define EXTERNDATA extern 281 282 /* only Pnmstitch uses UNREFERENCED_PARAMETER today (and I'm not sure why), 283 but it might come in handy some day. 284 */ 285 #if (!defined(UNREFERENCED_PARAMETER)) 286 # if (defined(__GNUC__)) 287 # define UNREFERENCED_PARAMETER(x) 288 # elif (defined(__USLC__) || defined(_M_XENIX)) 289 # define UNREFERENCED_PARAMETER(x) ((x)=(x)) 290 # else 291 # define UNREFERENCED_PARAMETER(x) (x) 292 # endif 293 #endif 294 295 #include <unistd.h> /* Get _LFS_LARGEFILE defined */ 296 #include <sys/types.h> 297 /* In GNU, _LFS_LARGEFILE means the "off_t" functions (ftello, etc.) are 298 available. In AIX, _AIXVERSION_430 means it's AIX Version 4.3.0 or 299 better, which seems to mean the "off_t" functions are available. 300 */ 301 #if defined(_LFS_LARGEFILE) || defined(_AIXVERSION_430) 302 typedef off_t pm_filepos; 303 #define FTELLO ftello 304 #define FSEEKO fseeko 305 #else 306 typedef long int pm_filepos; 307 #define FTELLO ftell 308 #define FSEEKO fseek 309 #endif 310 311 #if defined(_PLAN9) 312 #define TMPDIR "/tmp" 313 #else 314 /* Use POSIX value P_tmpdir from libc */ 315 #define TMPDIR P_tmpdir 316 #endif 317 318 /* Note that if you _don't_ have mkstemp(), you'd better have a safe 319 mktemp() or otherwise not be concerned about its unsafety. On some 320 systems, use of mktemp() makes it possible for a hacker to cause a 321 Netpbm program to access a file of the hacker's choosing when the 322 Netpbm program means to access its own temporary file. 323 */ 324 #ifdef __MINGW32__ 325 #define HAVE_MKSTEMP 0 326 #else 327 #define HAVE_MKSTEMP 1 328 #endif 329 330 typedef int qsort_comparison_fn(const void *, const void *); 331 /* A compare function to pass to <stdlib.h>'s qsort() */ 332 333 #if MSVCRT 334 #define pm_mkdir(dir, perm) _mkdir(dir) 335 #else 336 #define pm_mkdir(dir, perm) mkdir(dir, perm) 337 #endif 338 339 #if MSVCRT 340 #define pm_pipe _pipe 341 #else 342 #define pm_pipe pipe 343 #endif 344