The world's most popular open source database
00001 /* Copyright (C) 2000-2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* This is the include file that should be included 'first' in every C file. */ 00018 00019 #ifndef _global_h 00020 #define _global_h 00021 00022 #ifndef EMBEDDED_LIBRARY 00023 #define HAVE_REPLICATION 00024 #define HAVE_EXTERNAL_CLIENT 00025 #endif 00026 00027 #ifdef __CYGWIN__ 00028 /* We use a Unix API, so pretend it's not Windows */ 00029 #undef WIN 00030 #undef WIN32 00031 #undef _WIN 00032 #undef _WIN32 00033 #undef _WIN64 00034 #undef __WIN__ 00035 #undef __WIN32__ 00036 #define HAVE_ERRNO_AS_DEFINE 00037 #endif /* __CYGWIN__ */ 00038 00039 #if defined(__QNXNTO__) && !defined(FD_SETSIZE) 00040 #define FD_SETSIZE 1024 /* Max number of file descriptor bits in 00041 fd_set, used when calling 'select' 00042 Must be defined before including 00043 "sys/select.h" and "sys/time.h" 00044 */ 00045 #endif 00046 00047 00048 /* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */ 00049 #ifdef USE_PRAGMA_IMPLEMENTATION 00050 #define USE_PRAGMA_INTERFACE 00051 #endif 00052 00053 #if defined(i386) && !defined(__i386__) 00054 #define __i386__ 00055 #endif 00056 00057 /* Macros to make switching between C and C++ mode easier */ 00058 #ifdef __cplusplus 00059 #define C_MODE_START extern "C" { 00060 #define C_MODE_END } 00061 #else 00062 #define C_MODE_START 00063 #define C_MODE_END 00064 #endif 00065 00066 #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) 00067 #include <config-win.h> 00068 #elif defined(__NETWARE__) 00069 #include <my_config.h> 00070 #include <config-netware.h> 00071 #if defined(__cplusplus) && defined(inline) 00072 #undef inline /* fix configure problem */ 00073 #endif 00074 #else 00075 #include <my_config.h> 00076 #if defined(__cplusplus) && defined(inline) 00077 #undef inline /* fix configure problem */ 00078 #endif 00079 #endif /* _WIN32... */ 00080 00081 #ifndef EMBEDDED_LIBRARY 00082 #ifdef WITH_ROW_BASED_REPLICATION 00083 #define HAVE_ROW_BASED_REPLICATION 1 00084 #endif 00085 #ifdef WITH_NDB_BINLOG 00086 #define HAVE_NDB_BINLOG 1 00087 #endif 00088 #endif /* !EMBEDDED_LIBRARY */ 00089 00090 /* Some defines to avoid ifdefs in the code */ 00091 #ifndef NETWARE_YIELD 00092 #define NETWARE_YIELD 00093 #define NETWARE_SET_SCREEN_MODE(A) 00094 #endif 00095 00096 /* 00097 The macros below are borrowed from include/linux/compiler.h in the 00098 Linux kernel. Use them to indicate the likelyhood of the truthfulness 00099 of a condition. This serves two purposes - newer versions of gcc will be 00100 able to optimize for branch predication, which could yield siginficant 00101 performance gains in frequently executed sections of the code, and the 00102 other reason to use them is for documentation 00103 */ 00104 00105 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) 00106 #define __builtin_expect(x, expected_value) (x) 00107 #endif 00108 00109 #define likely(x) __builtin_expect((x),1) 00110 #define unlikely(x) __builtin_expect((x),0) 00111 00112 00113 /* 00114 The macros below are useful in optimising places where it has been 00115 discovered that cache misses stall the process and where a prefetch 00116 of the cache line can improve matters. This is available in GCC 3.1.1 00117 and later versions. 00118 PREFETCH_READ says that addr is going to be used for reading and that 00119 it is to be kept in caches if possible for a while 00120 PREFETCH_WRITE also says that the item to be cached is likely to be 00121 updated. 00122 The *LOCALITY scripts are also available for experimentation purposes 00123 mostly and should only be used if they are verified to improve matters. 00124 For more input see GCC manual (available in GCC 3.1.1 and later) 00125 */ 00126 00127 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10) 00128 #define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3) 00129 #define PREFETCH_WRITE(addr) \ 00130 __builtin_prefetch(addr, 1, 3) 00131 #define PREFETCH_READ_LOCALITY(addr, locality) \ 00132 __builtin_prefetch(addr, 0, locality) 00133 #define PREFETCH_WRITE_LOCALITY(addr, locality) \ 00134 __builtin_prefetch(addr, 1, locality) 00135 #else 00136 #define PREFETCH_READ(addr) 00137 #define PREFETCH_READ_LOCALITY(addr, locality) 00138 #define PREFETCH_WRITE(addr) 00139 #define PREFETCH_WRITE_LOCALITY(addr, locality) 00140 #endif 00141 00142 /* 00143 The following macro is used to ensure that code often used in most 00144 SQL statements and definitely for parts of the SQL processing are 00145 kept in a code segment by itself. This has the advantage that the 00146 risk of common code being overlapping in caches of the CPU is less. 00147 This can be a cause of big performance problems. 00148 Routines should be put in this category with care and when they are 00149 put there one should also strive to make as much of the error handling 00150 as possible (or uncommon code of the routine) to execute in a 00151 separate method to avoid moving to much code to this code segment. 00152 00153 It is very easy to use, simply add HOT_METHOD at the end of the 00154 function declaration. 00155 For more input see GCC manual (available in GCC 2.95 and later) 00156 */ 00157 00158 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94) 00159 #define HOT_METHOD \ 00160 __attribute__ ((section ("hot_code_section"))) 00161 #else 00162 #define HOT_METHOD 00163 #endif 00164 00165 /* 00166 The following macro is used to ensure that popular global variables 00167 are located next to each other to avoid that they contend for the 00168 same cache lines. 00169 00170 It is very easy to use, simply add HOT_DATA at the end of the declaration 00171 of the variable, the variable must be initialised because of the way 00172 that linker works so a declaration using HOT_DATA should look like: 00173 uint global_hot_data HOT_DATA = 0; 00174 For more input see GCC manual (available in GCC 2.95 and later) 00175 */ 00176 00177 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94) 00178 #define HOT_DATA \ 00179 __attribute__ ((section ("hot_data_section"))) 00180 #else 00181 #define HOT_DATA 00182 #endif 00183 00184 /* 00185 now let's figure out if inline functions are supported 00186 autoconf defines 'inline' to be empty, if not 00187 */ 00188 #define inline_test_1(X) X ## 1 00189 #define inline_test_2(X) inline_test_1(X) 00190 #if inline_test_2(inline) != 1 00191 #define HAVE_INLINE 00192 #endif 00193 #undef inline_test_2 00194 #undef inline_test_1 00195 00196 /* 00197 The following macros are used to control inlining a bit more than 00198 usual. These macros are used to ensure that inlining always or 00199 never occurs (independent of compilation mode). 00200 For more input see GCC manual (available in GCC 3.1.1 and later) 00201 */ 00202 00203 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10) 00204 #define ALWAYS_INLINE __attribute__ ((always_inline)) 00205 #define NEVER_INLINE __attribute__ ((noinline)) 00206 #else 00207 #define ALWAYS_INLINE 00208 #define NEVER_INLINE 00209 #endif 00210 00211 00212 /* Fix problem with S_ISLNK() on Linux */ 00213 #if defined(TARGET_OS_LINUX) 00214 #undef _GNU_SOURCE 00215 #define _GNU_SOURCE 1 00216 #endif 00217 00218 /* 00219 Temporary solution to solve bug#7156. Include "sys/types.h" before 00220 the thread headers, else the function madvise() will not be defined 00221 */ 00222 #if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) ) 00223 #include <sys/types.h> 00224 #endif 00225 00226 /* The client defines this to avoid all thread code */ 00227 #if defined(UNDEF_THREADS_HACK) 00228 #undef THREAD 00229 #undef HAVE_LINUXTHREADS 00230 #undef HAVE_NPTL 00231 #endif 00232 00233 #ifdef HAVE_THREADS_WITHOUT_SOCKETS 00234 /* MIT pthreads does not work with unix sockets */ 00235 #undef HAVE_SYS_UN_H 00236 #endif 00237 00238 #define __EXTENSIONS__ 1 /* We want some extension */ 00239 #ifndef __STDC_EXT__ 00240 #define __STDC_EXT__ 1 /* To get large file support on hpux */ 00241 #endif 00242 00243 /* 00244 Solaris 9 include file <sys/feature_tests.h> refers to X/Open document 00245 00246 System Interfaces and Headers, Issue 5 00247 00248 saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes, 00249 but apparently other systems (namely FreeBSD) don't agree. 00250 00251 On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600. 00252 Furthermore, it tests that if a program requires older standard 00253 (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be 00254 run on a new compiler (that defines _STDC_C99) and issues an #error. 00255 It's also an #error if a program requires new standard (_XOPEN_SOURCE=600 00256 or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99. 00257 00258 To add more to this mess, Sun Studio C compiler defines _STDC_C99 while 00259 C++ compiler does not! 00260 00261 So, in a desperate attempt to get correct prototypes for both 00262 C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500 00263 depending on the compiler's announced C standard support. 00264 00265 Cleaner solutions are welcome. 00266 */ 00267 #ifdef __sun 00268 #if __STDC_VERSION__ - 0 >= 199901L 00269 #define _XOPEN_SOURCE 600 00270 #else 00271 #define _XOPEN_SOURCE 500 00272 #endif 00273 #endif 00274 00275 #if defined(THREAD) && !defined(__WIN__) 00276 #ifndef _POSIX_PTHREAD_SEMANTICS 00277 #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */ 00278 #endif 00279 00280 #if !defined(SCO) 00281 #define _REENTRANT 1 /* Some thread libraries require this */ 00282 #endif 00283 #if !defined(_THREAD_SAFE) && !defined(_AIX) 00284 #define _THREAD_SAFE /* Required for OSF1 */ 00285 #endif 00286 #if defined(HPUX10) || defined(HPUX11) 00287 C_MODE_START /* HPUX needs this, signal.h bug */ 00288 #include <pthread.h> 00289 C_MODE_END 00290 #else 00291 #include <pthread.h> /* AIX must have this included first */ 00292 #endif 00293 #if !defined(SCO) && !defined(_REENTRANT) 00294 #define _REENTRANT 1 /* Threads requires reentrant code */ 00295 #endif 00296 #endif /* THREAD */ 00297 00298 /* Go around some bugs in different OS and compilers */ 00299 #ifdef _AIX /* By soren@t.dk */ 00300 #define _H_STRINGS 00301 #define _SYS_STREAM_H 00302 /* #define _AIX32_CURSES */ /* XXX: this breaks AIX 4.3.3 (others?). */ 00303 #define ulonglong2double(A) my_ulonglong2double(A) 00304 #define my_off_t2double(A) my_ulonglong2double(A) 00305 C_MODE_START 00306 double my_ulonglong2double(unsigned long long A); 00307 C_MODE_END 00308 #endif /* _AIX */ 00309 00310 #ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */ 00311 #undef HAVE_SNPRINTF 00312 #endif 00313 #ifdef HAVE_BROKEN_PREAD 00314 /* 00315 pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without 00316 installing the kernel patch PHKL_20349 or greater 00317 */ 00318 #undef HAVE_PREAD 00319 #undef HAVE_PWRITE 00320 #endif 00321 #if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus) 00322 #undef inline 00323 #define inline 00324 #endif 00325 00326 #ifdef UNDEF_HAVE_GETHOSTBYNAME_R /* For OSF4.x */ 00327 #undef HAVE_GETHOSTBYNAME_R 00328 #endif 00329 #ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */ 00330 #undef HAVE_INITGROUPS 00331 #endif 00332 00333 /* gcc/egcs issues */ 00334 00335 #if defined(__GNUC) && defined(__EXCEPTIONS) 00336 #error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile" 00337 #endif 00338 00339 00340 /* Fix a bug in gcc 2.8.0 on IRIX 6.2 */ 00341 #if SIZEOF_LONG == 4 && defined(__LONG_MAX__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 8) 00342 #undef __LONG_MAX__ /* Is a longlong value in gcc 2.8.0 ??? */ 00343 #define __LONG_MAX__ 2147483647 00344 #endif 00345 00346 /* egcs 1.1.2 has a problem with memcpy on Alpha */ 00347 #if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)) 00348 #define BAD_MEMCPY 00349 #endif 00350 00351 #if defined(_lint) && !defined(lint) 00352 #define lint 00353 #endif 00354 #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG) 00355 #define _LONG_LONG 1 /* For AIX string library */ 00356 #endif 00357 00358 #ifndef stdin 00359 #include <stdio.h> 00360 #endif 00361 #ifdef HAVE_STDLIB_H 00362 #include <stdlib.h> 00363 #endif 00364 #ifdef HAVE_STDDEF_H 00365 #include <stddef.h> 00366 #endif 00367 00368 #include <math.h> 00369 #ifdef HAVE_LIMITS_H 00370 #include <limits.h> 00371 #endif 00372 #ifdef HAVE_FLOAT_H 00373 #include <float.h> 00374 #endif 00375 00376 #ifdef HAVE_SYS_TYPES_H 00377 #include <sys/types.h> 00378 #endif 00379 #ifdef HAVE_FCNTL_H 00380 #include <fcntl.h> 00381 #endif 00382 #ifdef HAVE_SYS_TIMEB_H 00383 #include <sys/timeb.h> /* Avoid warnings on SCO */ 00384 #endif 00385 #if TIME_WITH_SYS_TIME 00386 # include <sys/time.h> 00387 # include <time.h> 00388 #else 00389 # if HAVE_SYS_TIME_H 00390 # include <sys/time.h> 00391 # else 00392 # include <time.h> 00393 # endif 00394 #endif /* TIME_WITH_SYS_TIME */ 00395 #ifdef HAVE_UNISTD_H 00396 #include <unistd.h> 00397 #endif 00398 #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA) 00399 #undef HAVE_ALLOCA 00400 #undef HAVE_ALLOCA_H 00401 #endif 00402 #ifdef HAVE_ALLOCA_H 00403 #include <alloca.h> 00404 #endif 00405 #ifdef HAVE_ATOMIC_ADD 00406 #define new my_arg_new 00407 #define need_to_restore_new 1 00408 C_MODE_START 00409 #include <asm/atomic.h> 00410 C_MODE_END 00411 #ifdef need_to_restore_new /* probably safer than #ifdef new */ 00412 #undef new 00413 #undef need_to_restore_new 00414 #endif 00415 #endif 00416 #include <errno.h> /* Recommended by debian */ 00417 /* We need the following to go around a problem with openssl on solaris */ 00418 #if defined(HAVE_CRYPT_H) 00419 #include <crypt.h> 00420 #endif 00421 00422 /* 00423 A lot of our programs uses asserts, so better to always include it 00424 This also fixes a problem when people uses DBUG_ASSERT without including 00425 assert.h 00426 */ 00427 #include <assert.h> 00428 00429 /* Go around some bugs in different OS and compilers */ 00430 #if defined (HPUX11) && defined(_LARGEFILE_SOURCE) 00431 #define _LARGEFILE64_SOURCE 00432 #endif 00433 #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H) 00434 #include <sys/stream.h> /* HPUX 10.20 defines ulong here. UGLY !!! */ 00435 #define HAVE_ULONG 00436 #endif 00437 #ifdef DONT_USE_FINITE /* HPUX 11.x has is_finite() */ 00438 #undef HAVE_FINITE 00439 #endif 00440 #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD) 00441 /* Fix bug in setrlimit */ 00442 #undef setrlimit 00443 #define setrlimit cma_setrlimit64 00444 #endif 00445 /* Declare madvise where it is not declared for C++, like Solaris */ 00446 #if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus) 00447 extern "C" int madvise(void *addr, size_t len, int behav); 00448 #endif 00449 00450 #ifdef __QNXNTO__ 00451 /* This has to be after include limits.h */ 00452 #define HAVE_ERRNO_AS_DEFINE 00453 #define HAVE_FCNTL_LOCK 00454 #undef HAVE_FINITE 00455 #undef LONGLONG_MIN /* These get wrongly defined in QNX 6.2 */ 00456 #undef LONGLONG_MAX /* standard system library 'limits.h' */ 00457 #ifdef __cplusplus 00458 #ifndef HAVE_RINT 00459 #define HAVE_RINT 00460 #endif /* rint() and isnan() functions are not */ 00461 #define rint(a) std::rint(a) /* visible in C++ scope due to an error */ 00462 #define isnan(a) std::isnan(a) /* in the usr/include/math.h on QNX */ 00463 #endif 00464 #endif 00465 00466 /* We can not live without the following defines */ 00467 00468 #define USE_MYFUNC 1 /* Must use syscall indirection */ 00469 #define MASTER 1 /* Compile without unireg */ 00470 #define ENGLISH 1 /* Messages in English */ 00471 #define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */ 00472 #define USE_REGEX 1 /* We want the use the regex library */ 00473 /* Do not define for ultra sparcs */ 00474 #define USE_BMOVE512 1 /* Use this unless system bmove is faster */ 00475 00476 #define QUOTE_ARG(x) #x /* Quote argument (before cpp) */ 00477 #define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */ 00478 00479 /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */ 00480 #ifdef I_AM_PARANOID 00481 #define DONT_ALLOW_USER_CHANGE 1 00482 #define DONT_USE_MYSQL_PWD 1 00483 #endif 00484 00485 /* Does the system remember a signal handler after a signal ? */ 00486 #ifndef HAVE_BSD_SIGNALS 00487 #define DONT_REMEMBER_SIGNAL 00488 #endif 00489 00490 /* Define void to stop lint from generating "null effekt" comments */ 00491 #ifndef DONT_DEFINE_VOID 00492 #ifdef _lint 00493 int __void__; 00494 #define VOID(X) (__void__ = (int) (X)) 00495 #else 00496 #undef VOID 00497 #define VOID(X) (X) 00498 #endif 00499 #endif /* DONT_DEFINE_VOID */ 00500 00501 #if defined(_lint) || defined(FORCE_INIT_OF_VARS) 00502 #define LINT_INIT(var) var=0 /* No uninitialize-warning */ 00503 #else 00504 #define LINT_INIT(var) 00505 #endif 00506 00507 #if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(HAVE_purify) 00508 #define PURIFY_OR_LINT_INIT(var) var=0 00509 #else 00510 #define PURIFY_OR_LINT_INIT(var) 00511 #endif 00512 00513 /* Define some useful general macros */ 00514 #if !defined(max) 00515 #define max(a, b) ((a) > (b) ? (a) : (b)) 00516 #define min(a, b) ((a) < (b) ? (a) : (b)) 00517 #endif 00518 00519 #if !defined(HAVE_UINT) 00520 #undef HAVE_UINT 00521 #define HAVE_UINT 00522 typedef unsigned int uint; 00523 typedef unsigned short ushort; 00524 #endif 00525 00526 #define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1) 00527 #define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0) 00528 #define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; } 00529 #define test(a) ((a) ? 1 : 0) 00530 #define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0) 00531 #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0) 00532 #define test_all_bits(a,b) (((a) & (b)) == (b)) 00533 #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1)) 00534 #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0]))) 00535 #ifndef HAVE_RINT 00536 #define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5)) 00537 #endif 00538 00539 /* Define some general constants */ 00540 #ifndef TRUE 00541 #define TRUE (1) /* Logical true */ 00542 #define FALSE (0) /* Logical false */ 00543 #endif 00544 00545 #if defined(__GNUC__) 00546 #define function_volatile volatile 00547 #define my_reinterpret_cast(A) reinterpret_cast<A> 00548 #define my_const_cast(A) const_cast<A> 00549 #elif !defined(my_reinterpret_cast) 00550 #define my_reinterpret_cast(A) (A) 00551 #define my_const_cast(A) (A) 00552 #endif 00553 #if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) 00554 #define __attribute__(A) 00555 #endif 00556 00557 /* 00558 Wen using the embedded library, users might run into link problems, 00559 duplicate declaration of __cxa_pure_virtual, solved by declaring it a 00560 weak symbol. 00561 */ 00562 #ifdef USE_MYSYS_NEW 00563 C_MODE_START 00564 int __cxa_pure_virtual () __attribute__ ((weak)); 00565 C_MODE_END 00566 #endif 00567 00568 /* From old s-system.h */ 00569 00570 /* 00571 Support macros for non ansi & other old compilers. Since such 00572 things are no longer supported we do nothing. We keep then since 00573 some of our code may still be needed to upgrade old customers. 00574 */ 00575 #define _VARARGS(X) X 00576 #define _STATIC_VARARGS(X) X 00577 #define _PC(X) X 00578 00579 #if defined(DBUG_ON) && defined(DBUG_OFF) 00580 #undef DBUG_OFF 00581 #endif 00582 00583 #if defined(_lint) && !defined(DBUG_OFF) 00584 #define DBUG_OFF 00585 #endif 00586 00587 #include <my_dbug.h> 00588 00589 #define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/ 00590 #define ASCII_BITS_USED 8 /* Bit char used */ 00591 #define NEAR_F /* No near function handling */ 00592 00593 /* Some types that is different between systems */ 00594 00595 typedef int File; /* File descriptor */ 00596 #ifndef Socket_defined 00597 typedef int my_socket; /* File descriptor for sockets */ 00598 #define INVALID_SOCKET -1 00599 #endif 00600 /* Type for fuctions that handles signals */ 00601 #define sig_handler RETSIGTYPE 00602 C_MODE_START 00603 typedef void (*sig_return)();/* Returns type from signal */ 00604 C_MODE_END 00605 #if defined(__GNUC__) && !defined(_lint) 00606 typedef char pchar; /* Mixed prototypes can take char */ 00607 typedef char puchar; /* Mixed prototypes can take char */ 00608 typedef char pbool; /* Mixed prototypes can take char */ 00609 typedef short pshort; /* Mixed prototypes can take short int */ 00610 typedef float pfloat; /* Mixed prototypes can take float */ 00611 #else 00612 typedef int pchar; /* Mixed prototypes can't take char */ 00613 typedef uint puchar; /* Mixed prototypes can't take char */ 00614 typedef int pbool; /* Mixed prototypes can't take char */ 00615 typedef int pshort; /* Mixed prototypes can't take short int */ 00616 typedef double pfloat; /* Mixed prototypes can't take float */ 00617 #endif 00618 C_MODE_START 00619 typedef int (*qsort_cmp)(const void *,const void *); 00620 typedef int (*qsort_cmp2)(void*, const void *,const void *); 00621 C_MODE_END 00622 #define qsort_t RETQSORTTYPE /* Broken GCC cant handle typedef !!!! */ 00623 #ifdef HAVE_SYS_SOCKET_H 00624 #include <sys/socket.h> 00625 #endif 00626 typedef SOCKET_SIZE_TYPE size_socket; 00627 00628 #ifndef SOCKOPT_OPTLEN_TYPE 00629 #define SOCKOPT_OPTLEN_TYPE size_socket 00630 #endif 00631 00632 /* file create flags */ 00633 00634 #ifndef O_SHARE /* Probably not windows */ 00635 #define O_SHARE 0 /* Flag to my_open for shared files */ 00636 #ifndef O_BINARY 00637 #define O_BINARY 0 /* Flag to my_open for binary files */ 00638 #endif 00639 #ifndef FILE_BINARY 00640 #define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */ 00641 #endif 00642 #ifdef HAVE_FCNTL 00643 #define HAVE_FCNTL_LOCK 00644 #define F_TO_EOF 0L /* Param to lockf() to lock rest of file */ 00645 #endif 00646 #endif /* O_SHARE */ 00647 00648 #ifndef O_TEMPORARY 00649 #define O_TEMPORARY 0 00650 #endif 00651 #ifndef O_SHORT_LIVED 00652 #define O_SHORT_LIVED 0 00653 #endif 00654 #ifndef O_NOFOLLOW 00655 #define O_NOFOLLOW 0 00656 #endif 00657 00658 /* additional file share flags for win32 */ 00659 #ifdef __WIN__ 00660 #define _SH_DENYRWD 0x110 /* deny read/write mode & delete */ 00661 #define _SH_DENYWRD 0x120 /* deny write mode & delete */ 00662 #define _SH_DENYRDD 0x130 /* deny read mode & delete */ 00663 #define _SH_DENYDEL 0x140 /* deny delete only */ 00664 #endif /* __WIN__ */ 00665 00666 00667 /* #define USE_RECORD_LOCK */ 00668 00669 /* Unsigned types supported by the compiler */ 00670 #define UNSINT8 /* unsigned int8 (char) */ 00671 #define UNSINT16 /* unsigned int16 */ 00672 #define UNSINT32 /* unsigned int32 */ 00673 00674 /* General constants */ 00675 #define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */ 00676 #define FN_LEN 256 /* Max file name len */ 00677 #define FN_HEADLEN 253 /* Max length of filepart of file name */ 00678 #define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */ 00679 #define FN_REFLEN 512 /* Max length of full path-name */ 00680 #define FN_EXTCHAR '.' 00681 #define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */ 00682 #define FN_CURLIB '.' /* ./ is used as abbrev for current dir */ 00683 #define FN_PARENTDIR ".." /* Parent directory; Must be a string */ 00684 00685 #ifndef FN_LIBCHAR 00686 #define FN_LIBCHAR '/' 00687 #define FN_ROOTDIR "/" 00688 #endif 00689 #define MY_NFILE 64 /* This is only used to save filenames */ 00690 #ifndef OS_FILE_LIMIT 00691 #define OS_FILE_LIMIT 65535 00692 #endif 00693 00694 /* #define EXT_IN_LIBNAME */ 00695 /* #define FN_NO_CASE_SENCE */ 00696 /* #define FN_UPPER_CASE TRUE */ 00697 00698 /* 00699 Io buffer size; Must be a power of 2 and a multiple of 512. May be 00700 smaller what the disk page size. This influences the speed of the 00701 isam btree library. eg to big to slow. 00702 */ 00703 #define IO_SIZE 4096 00704 /* 00705 How much overhead does malloc have. The code often allocates 00706 something like 1024-MALLOC_OVERHEAD bytes 00707 */ 00708 #ifdef SAFEMALLOC 00709 #define MALLOC_OVERHEAD (8+24+4) 00710 #else 00711 #define MALLOC_OVERHEAD 8 00712 #endif 00713 /* get memory in huncs */ 00714 #define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD) 00715 /* Typical record cash */ 00716 #define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD) 00717 /* Typical key cash */ 00718 #define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD) 00719 /* Default size of a key cache block */ 00720 #define KEY_CACHE_BLOCK_SIZE (uint) 1024 00721 00722 00723 /* Some things that this system doesn't have */ 00724 00725 #define NO_HASH /* Not needed anymore */ 00726 #ifdef __WIN__ 00727 #define NO_DIR_LIBRARY /* Not standar dir-library */ 00728 #define USE_MY_STAT_STRUCT /* For my_lib */ 00729 #endif 00730 00731 /* Some defines of functions for portability */ 00732 00733 #undef remove /* Crashes MySQL on SCO 5.0.0 */ 00734 #ifndef __WIN__ 00735 #define closesocket(A) close(A) 00736 #ifndef ulonglong2double 00737 #define ulonglong2double(A) ((double) (ulonglong) (A)) 00738 #define my_off_t2double(A) ((double) (my_off_t) (A)) 00739 #endif 00740 #endif 00741 00742 #ifndef offsetof 00743 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 00744 #endif 00745 #define ulong_to_double(X) ((double) (ulong) (X)) 00746 #define SET_STACK_SIZE(X) /* Not needed on real machines */ 00747 00748 #if !defined(HAVE_STRTOK_R) 00749 #define strtok_r(A,B,C) strtok((A),(B)) 00750 #endif 00751 00752 /* This is from the old m-machine.h file */ 00753 00754 #if SIZEOF_LONG_LONG > 4 00755 #define HAVE_LONG_LONG 1 00756 #endif 00757 00758 /* 00759 Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define 00760 ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined. 00761 Also on Windows we define these constants by hand in config-win.h. 00762 */ 00763 00764 #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN) 00765 #define LONGLONG_MIN ((long long) 0x8000000000000000LL) 00766 #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL) 00767 #endif 00768 00769 #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX) 00770 /* First check for ANSI C99 definition: */ 00771 #ifdef ULLONG_MAX 00772 #define ULONGLONG_MAX ULLONG_MAX 00773 #else 00774 #define ULONGLONG_MAX ((unsigned long long)(~0ULL)) 00775 #endif 00776 #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/ 00777 00778 #define INT_MIN32 (~0x7FFFFFFFL) 00779 #define INT_MAX32 0x7FFFFFFFL 00780 #define UINT_MAX32 0xFFFFFFFFL 00781 #define INT_MIN24 (~0x007FFFFF) 00782 #define INT_MAX24 0x007FFFFF 00783 #define UINT_MAX24 0x00FFFFFF 00784 #define INT_MIN16 (~0x7FFF) 00785 #define INT_MAX16 0x7FFF 00786 #define UINT_MAX16 0xFFFF 00787 #define INT_MIN8 (~0x7F) 00788 #define INT_MAX8 0x7F 00789 #define UINT_MAX8 0xFF 00790 00791 /* From limits.h instead */ 00792 #ifndef DBL_MIN 00793 #define DBL_MIN 4.94065645841246544e-324 00794 #define FLT_MIN ((float)1.40129846432481707e-45) 00795 #endif 00796 #ifndef DBL_MAX 00797 #define DBL_MAX 1.79769313486231470e+308 00798 #define FLT_MAX ((float)3.40282346638528860e+38) 00799 #endif 00800 #ifndef SSIZE_MAX 00801 #define SSIZE_MAX ((~((size_t) 0)) / 2) 00802 #endif 00803 00804 #if !defined(HAVE_ISINF) && !defined(isinf) 00805 #define isinf(X) 0 00806 #endif 00807 00808 /* Define missing math constants. */ 00809 #ifndef M_PI 00810 #define M_PI 3.14159265358979323846 00811 #endif 00812 #ifndef M_E 00813 #define M_E 2.7182818284590452354 00814 #endif 00815 #ifndef M_LN2 00816 #define M_LN2 0.69314718055994530942 00817 #endif 00818 00819 /* 00820 Max size that must be added to a so that we know Size to make 00821 adressable obj. 00822 */ 00823 #if SIZEOF_CHARP == 4 00824 typedef long my_ptrdiff_t; 00825 #else 00826 typedef long long my_ptrdiff_t; 00827 #endif 00828 00829 #if HAVE_SIZE_T 00830 typedef size_t my_size_t; 00831 #elif SIZEOF_CHARP <= SIZEOF_LONG 00832 typedef unsigned long my_size_t; 00833 #else 00834 typedef unsigned long long my_size_t; 00835 #endif 00836 00837 #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1)) 00838 #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double)) 00839 /* Size to make adressable obj. */ 00840 #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t))) 00841 /* Offset of field f in structure t */ 00842 #define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f) 00843 #define ADD_TO_PTR(ptr,size,type) (type) ((byte*) (ptr)+size) 00844 #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((byte*) (A) - (byte*) (B)) 00845 00846 #define NullS (char *) 0 00847 /* Nowdays we do not support MessyDos */ 00848 #ifndef NEAR 00849 #define NEAR /* Who needs segments ? */ 00850 #define FAR /* On a good machine */ 00851 #ifndef HUGE_PTR 00852 #define HUGE_PTR 00853 #endif 00854 #endif 00855 #if defined(__IBMC__) || defined(__IBMCPP__) 00856 /* This was _System _Export but caused a lot of warnings on _AIX43 */ 00857 #define STDCALL 00858 #elif !defined( STDCALL) 00859 #define STDCALL 00860 #endif 00861 00862 /* Typdefs for easyier portability */ 00863 00864 #if defined(VOIDTYPE) 00865 typedef void *gptr; /* Generic pointer */ 00866 #else 00867 typedef char *gptr; /* Generic pointer */ 00868 #endif 00869 #ifndef HAVE_UCHAR 00870 typedef unsigned char uchar; /* Short for unsigned char */ 00871 #endif 00872 00873 #ifndef HAVE_INT8 00874 typedef signed char int8; /* Signed integer >= 8 bits */ 00875 #endif 00876 #ifndef HAVE_UINT8 00877 typedef unsigned char uint8; /* Unsigned integer >= 8 bits */ 00878 #endif 00879 #ifndef HAVE_INT16 00880 typedef short int16; 00881 #endif 00882 #ifndef HAVE_UINT16 00883 typedef unsigned short uint16; 00884 #endif 00885 #if SIZEOF_INT == 4 00886 #ifndef HAVE_INT32 00887 typedef int int32; 00888 #endif 00889 #ifndef HAVE_UINT32 00890 typedef unsigned int uint32; 00891 #endif 00892 #elif SIZEOF_LONG == 4 00893 #ifndef HAVE_INT32 00894 typedef long int32; 00895 #endif 00896 #ifndef HAVE_UINT32 00897 typedef unsigned long uint32; 00898 #endif 00899 #else 00900 #error "Neither int or long is of 4 bytes width" 00901 #endif 00902 00903 #if !defined(HAVE_ULONG) && !defined(__USE_MISC) 00904 typedef unsigned long ulong; /* Short for unsigned long */ 00905 #endif 00906 #ifndef longlong_defined 00907 #if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8 00908 typedef unsigned long long int ulonglong; /* ulong or unsigned long long */ 00909 typedef long long int longlong; 00910 #else 00911 typedef unsigned long ulonglong; /* ulong or unsigned long long */ 00912 typedef long longlong; 00913 #endif 00914 #endif 00915 #ifndef HAVE_INT64 00916 typedef longlong int64; 00917 #endif 00918 #ifndef HAVE_UINT64 00919 typedef ulonglong uint64; 00920 #endif 00921 00922 #if defined(NO_CLIENT_LONG_LONG) 00923 typedef unsigned long my_ulonglong; 00924 #elif defined (__WIN__) 00925 typedef unsigned __int64 my_ulonglong; 00926 #else 00927 typedef unsigned long long my_ulonglong; 00928 #endif 00929 00930 #ifdef USE_RAID 00931 /* 00932 The following is done with a if to not get problems with pre-processors 00933 with late define evaluation 00934 */ 00935 #if SIZEOF_OFF_T == 4 00936 #define SYSTEM_SIZEOF_OFF_T 4 00937 #else 00938 #define SYSTEM_SIZEOF_OFF_T 8 00939 #endif 00940 #undef SIZEOF_OFF_T 00941 #define SIZEOF_OFF_T 8 00942 #else 00943 #define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T 00944 #endif /* USE_RAID */ 00945 00946 #if SIZEOF_OFF_T > 4 00947 typedef ulonglong my_off_t; 00948 #else 00949 typedef unsigned long my_off_t; 00950 #endif 00951 #define MY_FILEPOS_ERROR (~(my_off_t) 0) 00952 #if !defined(__WIN__) 00953 typedef off_t os_off_t; 00954 #endif 00955 00956 #if defined(__WIN__) 00957 #define socket_errno WSAGetLastError() 00958 #define SOCKET_EINTR WSAEINTR 00959 #define SOCKET_EAGAIN WSAEINPROGRESS 00960 #define SOCKET_ETIMEDOUT WSAETIMEDOUT 00961 #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK 00962 #define SOCKET_EADDRINUSE WSAEADDRINUSE 00963 #define SOCKET_ENFILE ENFILE 00964 #define SOCKET_EMFILE EMFILE 00965 #else /* Unix */ 00966 #define socket_errno errno 00967 #define closesocket(A) close(A) 00968 #define SOCKET_EINTR EINTR 00969 #define SOCKET_EAGAIN EAGAIN 00970 #define SOCKET_ETIMEDOUT SOCKET_EINTR 00971 #define SOCKET_EWOULDBLOCK EWOULDBLOCK 00972 #define SOCKET_EADDRINUSE EADDRINUSE 00973 #define SOCKET_ENFILE ENFILE 00974 #define SOCKET_EMFILE EMFILE 00975 #endif 00976 00977 typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */ 00978 typedef short int15; /* Most effective integer 0 <= x <= 32767 */ 00979 typedef char *my_string; /* String of characters */ 00980 typedef unsigned long size_s; /* Size of strings (In string-funcs) */ 00981 typedef int myf; /* Type of MyFlags in my_funcs */ 00982 #ifndef byte_defined 00983 typedef char byte; /* Smallest addressable unit */ 00984 #endif 00985 typedef char my_bool; /* Small bool */ 00986 #if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus)) 00987 typedef char bool; /* Ordinary boolean values 0 1 */ 00988 #endif 00989 /* Macros for converting *constants* to the right type */ 00990 #define INT8(v) (int8) (v) 00991 #define INT16(v) (int16) (v) 00992 #define INT32(v) (int32) (v) 00993 #define MYF(v) (myf) (v) 00994 00995 #ifndef LL 00996 #ifdef HAVE_LONG_LONG 00997 #define LL(A) A ## LL 00998 #else 00999 #define LL(A) A ## L 01000 #endif 01001 #endif 01002 01003 #ifndef ULL 01004 #ifdef HAVE_LONG_LONG 01005 #define ULL(A) A ## ULL 01006 #else 01007 #define ULL(A) A ## UL 01008 #endif 01009 #endif 01010 01011 /* 01012 Defines to make it possible to prioritize register assignments. No 01013 longer that important with modern compilers. 01014 */ 01015 #ifndef USING_X 01016 #define reg1 register 01017 #define reg2 register 01018 #define reg3 register 01019 #define reg4 register 01020 #define reg5 register 01021 #define reg6 register 01022 #define reg7 register 01023 #define reg8 register 01024 #define reg9 register 01025 #define reg10 register 01026 #define reg11 register 01027 #define reg12 register 01028 #define reg13 register 01029 #define reg14 register 01030 #define reg15 register 01031 #define reg16 register 01032 #endif 01033 01034 /* 01035 Sometimes we want to make sure that the variable is not put into 01036 a register in debugging mode so we can see its value in the core 01037 */ 01038 01039 #ifndef DBUG_OFF 01040 #define dbug_volatile volatile 01041 #else 01042 #define dbug_volatile 01043 #endif 01044 01045 /* Defines for time function */ 01046 #define SCALE_SEC 100 01047 #define SCALE_USEC 10000 01048 #define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */ 01049 #define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */ 01050 01051 #ifdef HAVE_TIMESPEC_TS_SEC 01052 #ifndef set_timespec 01053 #define set_timespec(ABSTIME,SEC) \ 01054 { \ 01055 (ABSTIME).ts_sec=time(0) + (time_t) (SEC); \ 01056 (ABSTIME).ts_nsec=0; \ 01057 } 01058 #endif /* !set_timespec */ 01059 #ifndef set_timespec_nsec 01060 #define set_timespec_nsec(ABSTIME,NSEC) \ 01061 { \ 01062 ulonglong now= my_getsystime() + (NSEC/100); \ 01063 (ABSTIME).ts_sec= (now / ULL(10000000)); \ 01064 (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \ 01065 } 01066 #endif /* !set_timespec_nsec */ 01067 #else 01068 #ifndef set_timespec 01069 #define set_timespec(ABSTIME,SEC) \ 01070 {\ 01071 struct timeval tv;\ 01072 gettimeofday(&tv,0);\ 01073 (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\ 01074 (ABSTIME).tv_nsec=tv.tv_usec*1000;\ 01075 } 01076 #endif /* !set_timespec */ 01077 #ifndef set_timespec_nsec 01078 #define set_timespec_nsec(ABSTIME,NSEC) \ 01079 {\ 01080 ulonglong now= my_getsystime() + (NSEC/100); \ 01081 (ABSTIME).tv_sec= (now / ULL(10000000)); \ 01082 (ABSTIME).tv_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \ 01083 } 01084 #endif /* !set_timespec_nsec */ 01085 #endif /* HAVE_TIMESPEC_TS_SEC */ 01086 01087 /* 01088 Define-funktions for reading and storing in machine independent format 01089 (low byte first) 01090 */ 01091 01092 /* Optimized store functions for Intel x86 */ 01093 #if defined(__i386__) && !defined(_WIN64) 01094 #define sint2korr(A) (*((int16 *) (A))) 01095 #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ 01096 (((uint32) 255L << 24) | \ 01097 (((uint32) (uchar) (A)[2]) << 16) |\ 01098 (((uint32) (uchar) (A)[1]) << 8) | \ 01099 ((uint32) (uchar) (A)[0])) : \ 01100 (((uint32) (uchar) (A)[2]) << 16) |\ 01101 (((uint32) (uchar) (A)[1]) << 8) | \ 01102 ((uint32) (uchar) (A)[0]))) 01103 #define sint4korr(A) (*((long *) (A))) 01104 #define uint2korr(A) (*((uint16 *) (A))) 01105 #ifdef HAVE_purify 01106 #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ 01107 (((uint32) ((uchar) (A)[1])) << 8) +\ 01108 (((uint32) ((uchar) (A)[2])) << 16)) 01109 #else 01110 /* 01111 ATTENTION ! 01112 01113 Please, note, uint3korr reads 4 bytes (not 3) ! 01114 It means, that you have to provide enough allocated space ! 01115 */ 01116 #define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) 01117 #endif 01118 #define uint4korr(A) (*((unsigned long *) (A))) 01119 #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ 01120 (((uint32) ((uchar) (A)[1])) << 8) +\ 01121 (((uint32) ((uchar) (A)[2])) << 16) +\ 01122 (((uint32) ((uchar) (A)[3])) << 24)) +\ 01123 (((ulonglong) ((uchar) (A)[4])) << 32)) 01124 #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \ 01125 (((uint32) ((uchar) (A)[1])) << 8) + \ 01126 (((uint32) ((uchar) (A)[2])) << 16) + \ 01127 (((uint32) ((uchar) (A)[3])) << 24)) + \ 01128 (((ulonglong) ((uchar) (A)[4])) << 32) + \ 01129 (((ulonglong) ((uchar) (A)[5])) << 40)) 01130 #define uint8korr(A) (*((ulonglong *) (A))) 01131 #define sint8korr(A) (*((longlong *) (A))) 01132 #define int2store(T,A) *((uint16*) (T))= (uint16) (A) 01133 #define int3store(T,A) do { *(T)= (uchar) ((A));\ 01134 *(T+1)=(uchar) (((uint) (A) >> 8));\ 01135 *(T+2)=(uchar) (((A) >> 16)); } while (0) 01136 #define int4store(T,A) *((long *) (T))= (long) (A) 01137 #define int5store(T,A) do { *(T)= (uchar)((A));\ 01138 *((T)+1)=(uchar) (((A) >> 8));\ 01139 *((T)+2)=(uchar) (((A) >> 16));\ 01140 *((T)+3)=(uchar) (((A) >> 24)); \ 01141 *((T)+4)=(uchar) (((A) >> 32)); } while(0) 01142 #define int6store(T,A) do { *(T)= (uchar)((A)); \ 01143 *((T)+1)=(uchar) (((A) >> 8)); \ 01144 *((T)+2)=(uchar) (((A) >> 16)); \ 01145 *((T)+3)=(uchar) (((A) >> 24)); \ 01146 *((T)+4)=(uchar) (((A) >> 32)); \ 01147 *((T)+5)=(uchar) (((A) >> 40)); } while(0) 01148 #define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A) 01149 01150 typedef union { 01151 double v; 01152 long m[2]; 01153 } doubleget_union; 01154 #define doubleget(V,M) \ 01155 do { doubleget_union _tmp; \ 01156 _tmp.m[0] = *((long*)(M)); \ 01157 _tmp.m[1] = *(((long*) (M))+1); \ 01158 (V) = _tmp.v; } while(0) 01159 #define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \ 01160 *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \ 01161 } while (0) 01162 #define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0) 01163 #define float8get(V,M) doubleget((V),(M)) 01164 #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float)) 01165 #define floatstore(T,V) memcpy((byte*)(T), (byte*)(&V),sizeof(float)) 01166 #define floatget(V,M) memcpy((byte*) &V,(byte*) (M),sizeof(float)) 01167 #define float8store(V,M) doublestore((V),(M)) 01168 #endif /* __i386__ */ 01169 01170 #ifndef sint2korr 01171 /* 01172 We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines 01173 were done before) 01174 */ 01175 #define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\ 01176 ((int16) ((int16) (A)[1]) << 8)) 01177 #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ 01178 (((uint32) 255L << 24) | \ 01179 (((uint32) (uchar) (A)[2]) << 16) |\ 01180 (((uint32) (uchar) (A)[1]) << 8) | \ 01181 ((uint32) (uchar) (A)[0])) : \ 01182 (((uint32) (uchar) (A)[2]) << 16) |\ 01183 (((uint32) (uchar) (A)[1]) << 8) | \ 01184 ((uint32) (uchar) (A)[0]))) 01185 #define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\ 01186 (((int32) ((uchar) (A)[1]) << 8)) +\ 01187 (((int32) ((uchar) (A)[2]) << 16)) +\ 01188 (((int32) ((int16) (A)[3]) << 24))) 01189 #define sint8korr(A) (longlong) uint8korr(A) 01190 #define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\ 01191 ((uint16) ((uchar) (A)[1]) << 8)) 01192 #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ 01193 (((uint32) ((uchar) (A)[1])) << 8) +\ 01194 (((uint32) ((uchar) (A)[2])) << 16)) 01195 #define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ 01196 (((uint32) ((uchar) (A)[1])) << 8) +\ 01197 (((uint32) ((uchar) (A)[2])) << 16) +\ 01198 (((uint32) ((uchar) (A)[3])) << 24)) 01199 #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ 01200 (((uint32) ((uchar) (A)[1])) << 8) +\ 01201 (((uint32) ((uchar) (A)[2])) << 16) +\ 01202 (((uint32) ((uchar) (A)[3])) << 24)) +\ 01203 (((ulonglong) ((uchar) (A)[4])) << 32)) 01204 #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \ 01205 (((uint32) ((uchar) (A)[1])) << 8) + \ 01206 (((uint32) ((uchar) (A)[2])) << 16) + \ 01207 (((uint32) ((uchar) (A)[3])) << 24)) + \ 01208 (((ulonglong) ((uchar) (A)[4])) << 32) + \ 01209 (((ulonglong) ((uchar) (A)[5])) << 40)) 01210 #define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ 01211 (((uint32) ((uchar) (A)[1])) << 8) +\ 01212 (((uint32) ((uchar) (A)[2])) << 16) +\ 01213 (((uint32) ((uchar) (A)[3])) << 24)) +\ 01214 (((ulonglong) (((uint32) ((uchar) (A)[4])) +\ 01215 (((uint32) ((uchar) (A)[5])) << 8) +\ 01216 (((uint32) ((uchar) (A)[6])) << 16) +\ 01217 (((uint32) ((uchar) (A)[7])) << 24))) <<\ 01218 32)) 01219 #define int2store(T,A) do { uint def_temp= (uint) (A) ;\ 01220 *((uchar*) (T))= (uchar)(def_temp); \ 01221 *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \ 01222 } while(0) 01223 #define int3store(T,A) do { /*lint -save -e734 */\ 01224 *((uchar*)(T))=(uchar) ((A));\ 01225 *((uchar*) (T)+1)=(uchar) (((A) >> 8));\ 01226 *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \ 01227 /*lint -restore */} while(0) 01228 #define int4store(T,A) do { *((char *)(T))=(char) ((A));\ 01229 *(((char *)(T))+1)=(char) (((A) >> 8));\ 01230 *(((char *)(T))+2)=(char) (((A) >> 16));\ 01231 *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0) 01232 #define int5store(T,A) do { *((char *)(T))=((A));\ 01233 *(((char *)(T))+1)=(((A) >> 8));\ 01234 *(((char *)(T))+2)=(((A) >> 16));\ 01235 *(((char *)(T))+3)=(((A) >> 24)); \ 01236 *(((char *)(T))+4)=(((A) >> 32)); } while(0) 01237 #define int6store(T,A) do { *((char *)(T))=((A));\ 01238 *(((char *)(T))+1)=(((A) >> 8)); \ 01239 *(((char *)(T))+2)=(((A) >> 16)); \ 01240 *(((char *)(T))+3)=(((A) >> 24)); \ 01241 *(((char *)(T))+4)=(((A) >> 32)); \ 01242 *(((char *)(T))+5)=(((A) >> 40)); } while(0) 01243 #define int8store(T,A) do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \ 01244 int4store((T),def_temp); \ 01245 int4store((T+4),def_temp2); } while(0) 01246 #ifdef WORDS_BIGENDIAN 01247 #define float4store(T,A) do { *(T)= ((byte *) &A)[3];\ 01248 *((T)+1)=(char) ((byte *) &A)[2];\ 01249 *((T)+2)=(char) ((byte *) &A)[1];\ 01250 *((T)+3)=(char) ((byte *) &A)[0]; } while(0) 01251 01252 #define float4get(V,M) do { float def_temp;\ 01253 ((byte*) &def_temp)[0]=(M)[3];\ 01254 ((byte*) &def_temp)[1]=(M)[2];\ 01255 ((byte*) &def_temp)[2]=(M)[1];\ 01256 ((byte*) &def_temp)[3]=(M)[0];\ 01257 (V)=def_temp; } while(0) 01258 #define float8store(T,V) do { *(T)= ((byte *) &V)[7];\ 01259 *((T)+1)=(char) ((byte *) &V)[6];\ 01260 *((T)+2)=(char) ((byte *) &V)[5];\ 01261 *((T)+3)=(char) ((byte *) &V)[4];\ 01262 *((T)+4)=(char) ((byte *) &V)[3];\ 01263 *((T)+5)=(char) ((byte *) &V)[2];\ 01264 *((T)+6)=(char) ((byte *) &V)[1];\ 01265 *((T)+7)=(char) ((byte *) &V)[0]; } while(0) 01266 01267 #define float8get(V,M) do { double def_temp;\ 01268 ((byte*) &def_temp)[0]=(M)[7];\ 01269 ((byte*) &def_temp)[1]=(M)[6];\ 01270 ((byte*) &def_temp)[2]=(M)[5];\ 01271 ((byte*) &def_temp)[3]=(M)[4];\ 01272 ((byte*) &def_temp)[4]=(M)[3];\ 01273 ((byte*) &def_temp)[5]=(M)[2];\ 01274 ((byte*) &def_temp)[6]=(M)[1];\ 01275 ((byte*) &def_temp)[7]=(M)[0];\ 01276 (V) = def_temp; } while(0) 01277 #else 01278 #define float4get(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float)) 01279 #define float4store(V,M) memcpy_fixed((byte*) V,(byte*) (&M),sizeof(float)) 01280 01281 #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) 01282 #define doublestore(T,V) do { *(((char*)T)+0)=(char) ((byte *) &V)[4];\ 01283 *(((char*)T)+1)=(char) ((byte *) &V)[5];\ 01284 *(((char*)T)+2)=(char) ((byte *) &V)[6];\ 01285 *(((char*)T)+3)=(char) ((byte *) &V)[7];\ 01286 *(((char*)T)+4)=(char) ((byte *) &V)[0];\ 01287 *(((char*)T)+5)=(char) ((byte *) &V)[1];\ 01288 *(((char*)T)+6)=(char) ((byte *) &V)[2];\ 01289 *(((char*)T)+7)=(char) ((byte *) &V)[3]; }\ 01290 while(0) 01291 #define doubleget(V,M) do { double def_temp;\ 01292 ((byte*) &def_temp)[0]=(M)[4];\ 01293 ((byte*) &def_temp)[1]=(M)[5];\ 01294 ((byte*) &def_temp)[2]=(M)[6];\ 01295 ((byte*) &def_temp)[3]=(M)[7];\ 01296 ((byte*) &def_temp)[4]=(M)[0];\ 01297 ((byte*) &def_temp)[5]=(M)[1];\ 01298 ((byte*) &def_temp)[6]=(M)[2];\ 01299 ((byte*) &def_temp)[7]=(M)[3];\ 01300 (V) = def_temp; } while(0) 01301 #endif /* __FLOAT_WORD_ORDER */ 01302 01303 #define float8get(V,M) doubleget((V),(M)) 01304 #define float8store(V,M) doublestore((V),(M)) 01305 #endif /* WORDS_BIGENDIAN */ 01306 01307 #endif /* sint2korr */ 01308 01309 /* 01310 Macro for reading 32-bit integer from network byte order (big-endian) 01311 from unaligned memory location. 01312 */ 01313 #define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\ 01314 (((uint32) ((uchar) (A)[2])) << 8) |\ 01315 (((uint32) ((uchar) (A)[1])) << 16) |\ 01316 (((uint32) ((uchar) (A)[0])) << 24)) 01317 /* 01318 Define-funktions for reading and storing in machine format from/to 01319 short/long to/from some place in memory V should be a (not 01320 register) variable, M is a pointer to byte 01321 */ 01322 01323 #ifdef WORDS_BIGENDIAN 01324 01325 #define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\ 01326 ((uint16) ((uint16) (M)[0]) << 8)); } while(0) 01327 #define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\ 01328 ((short) ((short) (M)[0]) << 8)); } while(0) 01329 #define longget(V,M) do { int32 def_temp;\ 01330 ((byte*) &def_temp)[0]=(M)[0];\ 01331 ((byte*) &def_temp)[1]=(M)[1];\ 01332 ((byte*) &def_temp)[2]=(M)[2];\ 01333 ((byte*) &def_temp)[3]=(M)[3];\ 01334 (V)=def_temp; } while(0) 01335 #define ulongget(V,M) do { uint32 def_temp;\ 01336 ((byte*) &def_temp)[0]=(M)[0];\ 01337 ((byte*) &def_temp)[1]=(M)[1];\ 01338 ((byte*) &def_temp)[2]=(M)[2];\ 01339 ((byte*) &def_temp)[3]=(M)[3];\ 01340 (V)=def_temp; } while(0) 01341 #define shortstore(T,A) do { uint def_temp=(uint) (A) ;\ 01342 *(((char*)T)+1)=(char)(def_temp); \ 01343 *(((char*)T)+0)=(char)(def_temp >> 8); } while(0) 01344 #define longstore(T,A) do { *(((char*)T)+3)=((A));\ 01345 *(((char*)T)+2)=(((A) >> 8));\ 01346 *(((char*)T)+1)=(((A) >> 16));\ 01347 *(((char*)T)+0)=(((A) >> 24)); } while(0) 01348 01349 #define floatget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float)) 01350 #define floatstore(T,V) memcpy_fixed((byte*) (T),(byte*)(&V),sizeof(float)) 01351 #define doubleget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double)) 01352 #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double)) 01353 #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong)) 01354 #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong)) 01355 01356 #else 01357 01358 #define ushortget(V,M) do { V = uint2korr(M); } while(0) 01359 #define shortget(V,M) do { V = sint2korr(M); } while(0) 01360 #define longget(V,M) do { V = sint4korr(M); } while(0) 01361 #define ulongget(V,M) do { V = uint4korr(M); } while(0) 01362 #define shortstore(T,V) int2store(T,V) 01363 #define longstore(T,V) int4store(T,V) 01364 #ifndef floatstore 01365 #define floatstore(T,V) memcpy_fixed((byte*) (T),(byte*) (&V),sizeof(float)) 01366 #define floatget(V,M) memcpy_fixed((byte*) &V, (byte*) (M), sizeof(float)) 01367 #endif 01368 #ifndef doubleget 01369 #define doubleget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double)) 01370 #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double)) 01371 #endif /* doubleget */ 01372 #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong)) 01373 #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong)) 01374 01375 #endif /* WORDS_BIGENDIAN */ 01376 01377 /* sprintf does not always return the number of bytes :- */ 01378 #ifdef SPRINTF_RETURNS_INT 01379 #define my_sprintf(buff,args) sprintf args 01380 #else 01381 #ifdef SPRINTF_RETURNS_PTR 01382 #define my_sprintf(buff,args) ((int)(sprintf args - buff)) 01383 #else 01384 #define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff)) 01385 #endif 01386 #endif 01387 01388 #ifndef THREAD 01389 #define thread_safe_increment(V,L) (V)++ 01390 #define thread_safe_add(V,C,L) (V)+=(C) 01391 #define thread_safe_sub(V,C,L) (V)-=(C) 01392 #define statistic_increment(V,L) (V)++ 01393 #define statistic_add(V,C,L) (V)+=(C) 01394 #endif 01395 01396 #ifdef HAVE_CHARSET_utf8 01397 #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8" 01398 #else 01399 #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME 01400 #endif 01401 01402 #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL) 01403 #define NO_EMBEDDED_ACCESS_CHECKS 01404 #endif 01405 01406 #ifdef HAVE_DLOPEN 01407 #if defined(__WIN__) 01408 #define dlsym(lib, name) GetProcAddress((HMODULE)lib, name) 01409 #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0) 01410 #define dlclose(lib) FreeLibrary((HMODULE)lib) 01411 #elif defined(HAVE_DLFCN_H) 01412 #include <dlfcn.h> 01413 #endif 01414 #endif 01415 01416 /* FreeBSD 2.2.2 does not define RTLD_NOW) */ 01417 #ifndef RTLD_NOW 01418 #define RTLD_NOW 1 01419 #endif 01420 01421 #ifndef HAVE_DLERROR 01422 #define dlerror() "" 01423 #endif 01424 01425 #endif /* my_global_h */
1.4.7

