1 /* 2 ** Copyright (c) 2006 D. Richard Hipp 3 ** 4 ** This program is free software; you can redistribute it and/or 5 ** modify it under the terms of the Simplified BSD License (also 6 ** known as the "2-Clause License" or "FreeBSD License".) 7 8 ** This program is distributed in the hope that it will be useful, 9 ** but without any warranty; without even the implied warranty of 10 ** merchantability or fitness for a particular purpose. 11 ** 12 ** Author contact information: 13 ** drh@hwaci.com 14 ** http://www.hwaci.com/drh/ 15 ** 16 ******************************************************************************* 17 ** 18 ** A common header file used by all modules. 19 */ 20 21 /* The following macros are necessary for large-file support under 22 ** some linux distributions, and possibly other unixes as well. 23 */ 24 #define _LARGE_FILE 1 25 #ifndef _FILE_OFFSET_BITS 26 # define _FILE_OFFSET_BITS 64 27 #endif 28 #define _LARGEFILE_SOURCE 1 29 30 /* Needed for various definitions... */ 31 #ifndef _GNU_SOURCE 32 # define _GNU_SOURCE 33 #endif 34 35 /* Make sure that in Win32 MinGW builds, _USE_32BIT_TIME_T is always defined. */ 36 #if defined(_WIN32) && !defined(_WIN64) && !defined(_MSC_VER) && !defined(_USE_32BIT_TIME_T) 37 # define _USE_32BIT_TIME_T 38 #endif 39 40 #ifdef HAVE_AUTOCONFIG_H 41 #include "autoconfig.h" 42 #endif 43 44 /* Enable the hardened SHA1 implemenation by default */ 45 #ifndef FOSSIL_HARDENED_SHA1 46 # define FOSSIL_HARDENED_SHA1 1 47 #endif 48 49 #ifndef _RC_COMPILE_ 50 51 /* 52 ** System header files used by all modules 53 */ 54 #include <unistd.h> 55 #include <stdio.h> 56 #include <stdlib.h> 57 /* #include <ctype.h> // do not use - causes problems */ 58 #include <string.h> 59 #include <stdarg.h> 60 #include <assert.h> 61 62 #endif 63 64 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) 65 # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) 66 typedef int socklen_t; 67 # endif 68 # ifndef _WIN32 69 # define _WIN32 70 # endif 71 # include <io.h> 72 # include <fcntl.h> 73 # undef popen 74 # define popen _popen 75 # undef pclose 76 # define pclose _pclose 77 #else 78 # include <sys/types.h> 79 # include <signal.h> 80 # include <pwd.h> 81 #endif 82 83 /* 84 ** Utility macro to wrap an argument with double quotes. 85 */ 86 #if !defined(COMPILER_STRINGIFY) 87 # define COMPILER_STRINGIFY(x) COMPILER_STRINGIFY1(x) 88 # define COMPILER_STRINGIFY1(x) #x 89 #endif 90 91 /* 92 ** Define the compiler variant, used to compile the project 93 */ 94 #if !defined(COMPILER_NAME) 95 # if defined(__DMC__) 96 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 97 # define COMPILER_NAME "dmc-" COMPILER_VERSION 98 # else 99 # define COMPILER_NAME "dmc" 100 # endif 101 # elif defined(__POCC__) 102 # if defined(_M_X64) 103 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 104 # define COMPILER_NAME "pellesc64-" COMPILER_VERSION 105 # else 106 # define COMPILER_NAME "pellesc64" 107 # endif 108 # else 109 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 110 # define COMPILER_NAME "pellesc32-" COMPILER_VERSION 111 # else 112 # define COMPILER_NAME "pellesc32" 113 # endif 114 # endif 115 # elif defined(__clang__) 116 # if !defined(COMPILER_VERSION) 117 # if defined(__clang_version__) 118 # define COMPILER_VERSION __clang_version__ 119 # endif 120 # endif 121 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 122 # define COMPILER_NAME "clang-" COMPILER_VERSION 123 # else 124 # define COMPILER_NAME "clang" 125 # endif 126 # elif defined(_MSC_VER) 127 # if !defined(COMPILER_VERSION) 128 # define COMPILER_VERSION COMPILER_STRINGIFY(_MSC_VER) 129 # endif 130 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 131 # define COMPILER_NAME "msc-" COMPILER_VERSION 132 # else 133 # define COMPILER_NAME "msc" 134 # endif 135 # elif defined(__MINGW32__) 136 # if !defined(COMPILER_VERSION) 137 # if defined(__MINGW_VERSION) 138 # if defined(__GNUC__) 139 # if defined(__VERSION__) 140 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW_VERSION) "-gcc-" __VERSION__ 141 # else 142 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW_VERSION) "-gcc" 143 # endif 144 # else 145 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW_VERSION) 146 # endif 147 # elif defined(__MINGW32_VERSION) 148 # if defined(__GNUC__) 149 # if defined(__VERSION__) 150 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) "-gcc-" __VERSION__ 151 # else 152 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) "-gcc" 153 # endif 154 # else 155 # define COMPILER_VERSION COMPILER_STRINGIFY(__MINGW32_VERSION) 156 # endif 157 # endif 158 # endif 159 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 160 # define COMPILER_NAME "mingw32-" COMPILER_VERSION 161 # else 162 # define COMPILER_NAME "mingw32" 163 # endif 164 # elif defined(__GNUC__) 165 # if !defined(COMPILER_VERSION) 166 # if defined(__VERSION__) 167 # define COMPILER_VERSION __VERSION__ 168 # endif 169 # endif 170 # if defined(COMPILER_VERSION) && !defined(NO_COMPILER_VERSION) 171 # define COMPILER_NAME "gcc-" COMPILER_VERSION 172 # else 173 # define COMPILER_NAME "gcc" 174 # endif 175 # elif defined(_WIN32) 176 # define COMPILER_NAME "win32" 177 # else 178 # define COMPILER_NAME "unknown" 179 # endif 180 #endif 181 182 #if !defined(_RC_COMPILE_) && !defined(SQLITE_AMALGAMATION) 183 184 /* 185 ** MSVC does not include the "stdint.h" header file until 2010. 186 */ 187 #if defined(_MSC_VER) && _MSC_VER<1600 188 typedef __int8 int8_t; 189 typedef unsigned __int8 uint8_t; 190 typedef __int32 int32_t; 191 typedef unsigned __int32 uint32_t; 192 typedef __int64 int64_t; 193 typedef unsigned __int64 uint64_t; 194 #else 195 # include <stdint.h> 196 #endif 197 198 #if USE_SEE && !defined(SQLITE_HAS_CODEC) 199 # define SQLITE_HAS_CODEC 200 #endif 201 #include "sqlite3.h" 202 203 /* 204 ** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257. 205 */ 206 #if HAVE_GETPASSPHRASE 207 #define getpass getpassphrase 208 #endif 209 210 /* 211 ** Typedef for a 64-bit integer 212 */ 213 typedef sqlite3_int64 i64; 214 typedef sqlite3_uint64 u64; 215 216 /* 217 ** 8-bit types 218 */ 219 typedef unsigned char u8; 220 typedef signed char i8; 221 222 /* In the timeline, check-in messages are truncated at the first space 223 ** that is more than MX_CKIN_MSG from the beginning, or at the first 224 ** paragraph break that is more than MN_CKIN_MSG from the beginning. 225 */ 226 #define MN_CKIN_MSG 100 227 #define MX_CKIN_MSG 300 228 229 /* 230 ** The following macros are used to cast pointers to integers and 231 ** integers to pointers. The way you do this varies from one compiler 232 ** to the next, so we have developed the following set of #if statements 233 ** to generate appropriate macros for a wide range of compilers. 234 ** 235 ** The correct "ANSI" way to do this is to use the intptr_t type. 236 ** Unfortunately, that typedef is not available on all compilers, or 237 ** if it is available, it requires an #include of specific headers 238 ** that vary from one machine to the next. 239 */ 240 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ 241 # define FOSSIL_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) 242 # define FOSSIL_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) 243 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */ 244 # define FOSSIL_INT_TO_PTR(X) ((void*)&((char*)0)[X]) 245 # define FOSSIL_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) 246 #else /* Generates a warning - but it always works */ 247 # define FOSSIL_INT_TO_PTR(X) ((void*)(X)) 248 # define FOSSIL_PTR_TO_INT(X) ((int)(X)) 249 #endif 250 251 /* 252 ** A marker for functions that never return. 253 */ 254 #if defined(__GNUC__) || defined(__clang__) 255 # define NORETURN __attribute__((__noreturn__)) 256 # define NULL_SENTINEL __attribute__((sentinel)) 257 #elif defined(_MSC_VER) && (_MSC_VER >= 1310) 258 # define NORETURN __declspec(noreturn) 259 # define NULL_SENTINEL 260 #else 261 # define NORETURN 262 # define NULL_SENTINEL 263 #endif 264 265 /* 266 ** Number of elements in an array 267 */ 268 #define count(X) (int)(sizeof(X)/sizeof(X[0])) 269 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0])) 270 271 /* 272 ** The pledge() interface is currently only available on OpenBSD 5.9 273 ** and later. Make calls to fossil_pledge() no-ops on all platforms 274 ** that omit the HAVE_PLEDGE configuration parameter. 275 */ 276 #if !defined(HAVE_PLEDGE) 277 # define fossil_pledge(A) 278 #endif 279 280 281 #endif /* _RC_COMPILE_ */ 282