1 /* 2 * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * * Neither the name of Redis nor the names of its contributors may be used 14 * to endorse or promote products derived from this software without 15 * specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef __CONFIG_H 31 #define __CONFIG_H 32 33 #ifdef __APPLE__ 34 #include <AvailabilityMacros.h> 35 #endif 36 37 #ifdef __linux__ 38 #include <linux/version.h> 39 #include <features.h> 40 #endif 41 42 /* Define redis_fstat to fstat or fstat64() */ 43 #if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6) 44 #define redis_fstat fstat64 45 #define redis_stat stat64 46 #else 47 #define redis_fstat fstat 48 #define redis_stat stat 49 #endif 50 51 /* Test for proc filesystem */ 52 #ifdef __linux__ 53 #define HAVE_PROC_STAT 1 54 #define HAVE_PROC_MAPS 1 55 #define HAVE_PROC_SMAPS 1 56 #define HAVE_PROC_SOMAXCONN 1 57 #endif 58 59 /* Test for task_info() */ 60 #if defined(__APPLE__) 61 #define HAVE_TASKINFO 1 62 #endif 63 64 /* Test for backtrace() */ 65 #if defined(__APPLE__) || (defined(__linux__) && defined(__GLIBC__)) 66 #define HAVE_BACKTRACE 1 67 #endif 68 69 /* MSG_NOSIGNAL. */ 70 #ifdef __linux__ 71 #define HAVE_MSG_NOSIGNAL 1 72 #endif 73 74 /* Test for polling API */ 75 #ifdef __linux__ 76 #define HAVE_EPOLL 1 77 #endif 78 79 #if (defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_6)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__) 80 #define HAVE_KQUEUE 1 81 #endif 82 83 #ifdef __sun 84 #include <sys/feature_tests.h> 85 #ifdef _DTRACE_VERSION 86 #define HAVE_EVPORT 1 87 #endif 88 #endif 89 90 /* Define aof_fsync to fdatasync() in Linux and fsync() for all the rest */ 91 #ifdef __linux__ 92 #define aof_fsync fdatasync 93 #else 94 #define aof_fsync fsync 95 #endif 96 97 /* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use 98 * the plain fsync() call. */ 99 #ifdef __linux__ 100 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) 101 #if (LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6)) 102 #define HAVE_SYNC_FILE_RANGE 1 103 #endif 104 #else 105 #if (LINUX_VERSION_CODE >= 0x020611) 106 #define HAVE_SYNC_FILE_RANGE 1 107 #endif 108 #endif 109 #endif 110 111 #ifdef HAVE_SYNC_FILE_RANGE 112 #define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE) 113 #else 114 #define rdb_fsync_range(fd,off,size) fsync(fd) 115 #endif 116 117 /* Check if we can use setproctitle(). 118 * BSD systems have support for it, we provide an implementation for 119 * Linux and osx. */ 120 #if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__) 121 #define USE_SETPROCTITLE 122 #endif 123 124 #if ((defined __linux && defined(__GLIBC__)) || defined __APPLE__) 125 #define USE_SETPROCTITLE 126 #define INIT_SETPROCTITLE_REPLACEMENT 127 void spt_init(int argc, char *argv[]); 128 void setproctitle(const char *fmt, ...); 129 #endif 130 131 /* Byte ordering detection */ 132 #include <sys/types.h> /* This will likely define BYTE_ORDER */ 133 134 #ifndef BYTE_ORDER 135 #if (BSD >= 199103) 136 # include <machine/endian.h> 137 #else 138 #if defined(linux) || defined(__linux__) 139 # include <endian.h> 140 #else 141 #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ 142 #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ 143 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ 144 145 #if defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \ 146 defined(vax) || defined(ns32000) || defined(sun386) || \ 147 defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ 148 defined(__alpha__) || defined(__alpha) 149 #define BYTE_ORDER LITTLE_ENDIAN 150 #endif 151 152 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \ 153 defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \ 154 defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\ 155 defined(apollo) || defined(__convex__) || defined(_CRAY) || \ 156 defined(__hppa) || defined(__hp9000) || \ 157 defined(__hp9000s300) || defined(__hp9000s700) || \ 158 defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) 159 #define BYTE_ORDER BIG_ENDIAN 160 #endif 161 #endif /* linux */ 162 #endif /* BSD */ 163 #endif /* BYTE_ORDER */ 164 165 /* Sometimes after including an OS-specific header that defines the 166 * endianess we end with __BYTE_ORDER but not with BYTE_ORDER that is what 167 * the Redis code uses. In this case let's define everything without the 168 * underscores. */ 169 #ifndef BYTE_ORDER 170 #ifdef __BYTE_ORDER 171 #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) 172 #ifndef LITTLE_ENDIAN 173 #define LITTLE_ENDIAN __LITTLE_ENDIAN 174 #endif 175 #ifndef BIG_ENDIAN 176 #define BIG_ENDIAN __BIG_ENDIAN 177 #endif 178 #if (__BYTE_ORDER == __LITTLE_ENDIAN) 179 #define BYTE_ORDER LITTLE_ENDIAN 180 #else 181 #define BYTE_ORDER BIG_ENDIAN 182 #endif 183 #endif 184 #endif 185 #endif 186 187 #if !defined(BYTE_ORDER) || \ 188 (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN) 189 /* you must determine what the correct bit order is for 190 * your compiler - the next line is an intentional error 191 * which will force your compiles to bomb until you fix 192 * the above macros. 193 */ 194 #error "Undefined or invalid BYTE_ORDER" 195 #endif 196 197 #if (__i386 || __amd64 || __powerpc__) && __GNUC__ 198 #define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 199 #if defined(__clang__) 200 #define HAVE_ATOMIC 201 #endif 202 #if (defined(__GLIBC__) && defined(__GLIBC_PREREQ)) 203 #if (GNUC_VERSION >= 40100 && __GLIBC_PREREQ(2, 6)) 204 #define HAVE_ATOMIC 205 #endif 206 #endif 207 #endif 208 209 #endif 210