home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / mySQL / mysql-5.0.1-alpha-snapshot-win / data1.cab / Development / include / my_global.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-07-28  |  38.0 KB  |  1,203 lines

  1. /* Copyright (C) 2000-2003 MySQL AB
  2.  
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2 of the License, or
  6.    (at your option) any later version.
  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.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  16.  
  17. /* This is the include file that should be included 'first' in every C file. */
  18.  
  19. #ifndef _global_h
  20. #define _global_h
  21.  
  22. #ifndef EMBEDDED_LIBRARY
  23. #define HAVE_REPLICATION
  24. #define HAVE_EXTERNAL_CLIENT
  25. #endif
  26.  
  27. #if defined( __EMX__) && !defined( MYSQL_SERVER)
  28. /* moved here to use below VOID macro redefinition */
  29. #define INCL_BASE
  30. #define INCL_NOPMAPI
  31. #include <os2.h>
  32. #endif /* __EMX__ */
  33.  
  34. #ifdef __CYGWIN__
  35. /* We use a Unix API, so pretend it's not Windows */
  36. #undef WIN
  37. #undef WIN32
  38. #undef _WIN
  39. #undef _WIN32
  40. #undef _WIN64
  41. #undef __WIN__
  42. #undef __WIN32__
  43. #define HAVE_ERRNO_AS_DEFINE
  44. #endif /* __CYGWIN__ */
  45.  
  46. #if defined(i386) && !defined(__i386__)
  47. #define __i386__
  48. #endif
  49.  
  50. /* Macros to make switching between C and C++ mode easier */
  51. #ifdef __cplusplus
  52. #define C_MODE_START    extern "C" {
  53. #define C_MODE_END    }
  54. #else
  55. #define C_MODE_START
  56. #define C_MODE_END
  57. #endif
  58.  
  59. #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
  60. #include <config-win.h>
  61. #elif defined(OS2)
  62. #include <config-os2.h>
  63. #elif defined(__NETWARE__)
  64. #include <my_config.h>
  65. #include <config-netware.h>
  66. #if defined(__cplusplus) && defined(inline)
  67. #undef inline                /* fix configure problem */
  68. #endif
  69. #else
  70. #include <my_config.h>
  71. #if defined(__cplusplus) && defined(inline)
  72. #undef inline                /* fix configure problem */
  73. #endif
  74. #endif /* _WIN32... */
  75.  
  76. /* Some defines to avoid ifdefs in the code */
  77. #ifndef NETWARE_YIELD
  78. #define NETWARE_YIELD
  79. #define NETWARE_SET_SCREEN_MODE(A)
  80. #endif
  81.  
  82. /*
  83.   The macros below are borrowed from include/linux/compiler.h in the
  84.   Linux kernel. Use them to indicate the likelyhood of the truthfulness
  85.   of a condition. This serves two purposes - newer versions of gcc will be
  86.   able to optimize for branch predication, which could yield siginficant
  87.   performance gains in frequently executed sections of the code, and the
  88.   other reason to use them is for documentation
  89. */
  90.  
  91. #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
  92. #define __builtin_expect(x, expected_value) (x)
  93. #endif
  94.  
  95. #define likely(x)    __builtin_expect((x),1)
  96. #define unlikely(x)    __builtin_expect((x),0)
  97.  
  98.  
  99. /* Fix problem with S_ISLNK() on Linux */
  100. #if defined(HAVE_LINUXTHREADS)
  101. #undef  _GNU_SOURCE
  102. #define _GNU_SOURCE 1
  103. #endif
  104.  
  105. /* The client defines this to avoid all thread code */
  106. #if defined(UNDEF_THREADS_HACK)
  107. #undef THREAD
  108. #undef HAVE_mit_thread
  109. #undef HAVE_LINUXTHREADS
  110. #undef HAVE_UNIXWARE7_THREADS
  111. #endif
  112.  
  113. #ifdef HAVE_THREADS_WITHOUT_SOCKETS
  114. /* MIT pthreads does not work with unix sockets */
  115. #undef HAVE_SYS_UN_H
  116. #endif
  117.  
  118. #define __EXTENSIONS__ 1    /* We want some extension */
  119. #ifndef __STDC_EXT__
  120. #define __STDC_EXT__ 1          /* To get large file support on hpux */
  121. #endif
  122.  
  123. #if defined(THREAD) && !defined(__WIN__) && !defined(OS2)
  124. #ifndef _POSIX_PTHREAD_SEMANTICS
  125. #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
  126. #endif
  127.  
  128. #if !defined(SCO)
  129. #define _REENTRANT    1    /* Some thread libraries require this */
  130. #endif
  131. #if !defined(_THREAD_SAFE) && !defined(_AIX)
  132. #define _THREAD_SAFE            /* Required for OSF1 */
  133. #endif
  134. #ifndef HAVE_mit_thread
  135. #ifdef HAVE_UNIXWARE7_THREADS
  136. #include <thread.h>
  137. #else
  138. #include <pthread.h>        /* AIX must have this included first */
  139. #endif /* HAVE_UNIXWARE7_THREADS */
  140. #endif /* HAVE_mit_thread */
  141. #if !defined(SCO) && !defined(_REENTRANT)
  142. #define _REENTRANT    1    /* Threads requires reentrant code */
  143. #endif
  144. #endif /* THREAD */
  145.  
  146. /* Go around some bugs in different OS and compilers */
  147. #ifdef _AIX            /* By soren@t.dk */
  148. #define _H_STRINGS
  149. #define _SYS_STREAM_H
  150. /* #define _AIX32_CURSES */    /* XXX: this breaks AIX 4.3.3 (others?). */
  151. #define ulonglong2double(A) my_ulonglong2double(A)
  152. #define my_off_t2double(A)  my_ulonglong2double(A)
  153. C_MODE_START
  154. double my_ulonglong2double(unsigned long long A);
  155. C_MODE_END
  156. #endif /* _AIX */
  157.  
  158. #ifdef HAVE_BROKEN_SNPRINTF    /* HPUX 10.20 don't have this defined */
  159. #undef HAVE_SNPRINTF
  160. #endif
  161. #ifdef HAVE_BROKEN_PREAD
  162. /*
  163.   pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without
  164.   installing the kernel patch PHKL_20349 or greater
  165. */
  166. #undef HAVE_PREAD
  167. #undef HAVE_PWRITE
  168. #endif
  169. #if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
  170. #undef inline
  171. #define inline
  172. #endif
  173.  
  174. #ifdef UNDEF_HAVE_GETHOSTBYNAME_R        /* For OSF4.x */
  175. #undef HAVE_GETHOSTBYNAME_R
  176. #endif
  177. #ifdef UNDEF_HAVE_INITGROUPS            /* For AIX 4.3 */
  178. #undef HAVE_INITGROUPS
  179. #endif
  180.  
  181. /* gcc/egcs issues */
  182.  
  183. #if defined(__GNUC) && defined(__EXCEPTIONS)
  184. #error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
  185. #endif
  186.  
  187.  
  188. /* Fix a bug in gcc 2.8.0 on IRIX 6.2 */
  189. #if SIZEOF_LONG == 4 && defined(__LONG_MAX__)
  190. #undef __LONG_MAX__             /* Is a longlong value in gcc 2.8.0 ??? */
  191. #define __LONG_MAX__ 2147483647
  192. #endif
  193.  
  194. /* Fix problem when linking c++ programs with gcc 3.x */
  195. #ifdef DEFINE_CXA_PURE_VIRTUAL
  196. #define FIX_GCC_LINKING_PROBLEM \
  197. extern "C" { int __cxa_pure_virtual() {\
  198.   DBUG_ASSERT("Pure virtual method called." == "Aborted");\
  199.   return 0;\
  200. } }
  201. #else
  202. #define FIX_GCC_LINKING_PROBLEM
  203. #endif
  204.  
  205. /* egcs 1.1.2 has a problem with memcpy on Alpha */
  206. #if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 &&  __GNUC_MINOR__ >= 95))
  207. #define BAD_MEMCPY
  208. #endif
  209.  
  210. /* In Linux-alpha we have atomic.h if we are using gcc */
  211. #if defined(HAVE_LINUXTHREADS) && defined(__GNUC__) && defined(__alpha__) && (__GNUC__ > 2 || ( __GNUC__ == 2 &&  __GNUC_MINOR__ >= 95)) && !defined(HAVE_ATOMIC_ADD)
  212. #define HAVE_ATOMIC_ADD
  213. #define HAVE_ATOMIC_SUB
  214. #endif
  215.  
  216. /* In Linux-ia64 including atomic.h will give us an error */
  217. #if (defined(HAVE_LINUXTHREADS) && defined(__GNUC__) && (defined(__ia64__)||defined(__powerpc64__))) || !defined(THREAD)
  218. #undef HAVE_ATOMIC_ADD
  219. #undef HAVE_ATOMIC_SUB
  220. #endif
  221.  
  222. #if defined(_lint) && !defined(lint)
  223. #define lint
  224. #endif
  225. #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
  226. #define _LONG_LONG 1        /* For AIX string library */
  227. #endif
  228.  
  229. #ifndef stdin
  230. #include <stdio.h>
  231. #endif
  232. #ifdef HAVE_STDLIB_H
  233. #include <stdlib.h>
  234. #endif
  235. #ifdef HAVE_STDDEF_H
  236. #include <stddef.h>
  237. #endif
  238.  
  239. #include <math.h>
  240. #ifdef HAVE_LIMITS_H
  241. #include <limits.h>
  242. #endif
  243. #ifdef HAVE_FLOAT_H
  244. #include <float.h>
  245. #endif
  246.  
  247. #ifdef HAVE_SYS_TYPES_H
  248. #include <sys/types.h>
  249. #endif
  250. #ifdef HAVE_FCNTL_H
  251. #include <fcntl.h>
  252. #endif
  253. #ifdef HAVE_SYS_TIMEB_H
  254. #include <sys/timeb.h>                /* Avoid warnings on SCO */
  255. #endif
  256. #if TIME_WITH_SYS_TIME
  257. # include <sys/time.h>
  258. # include <time.h>
  259. #else
  260. # if HAVE_SYS_TIME_H
  261. #  include <sys/time.h>
  262. # else
  263. #  include <time.h>
  264. # endif
  265. #endif /* TIME_WITH_SYS_TIME */
  266. #ifdef HAVE_UNISTD_H
  267. #if defined(HAVE_OPENSSL) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__)
  268. #define crypt unistd_crypt
  269. #endif
  270. #include <unistd.h>
  271. #ifdef HAVE_OPENSSL
  272. #undef crypt
  273. #endif
  274. #endif
  275. #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
  276. #undef HAVE_ALLOCA
  277. #undef HAVE_ALLOCA_H
  278. #endif
  279. #ifdef HAVE_ALLOCA_H
  280. #include <alloca.h>
  281. #endif
  282. #ifdef HAVE_ATOMIC_ADD
  283. #define __SMP__
  284. #ifdef HAVE_LINUX_CONFIG_H
  285. #include <linux/config.h>    /* May define CONFIG_SMP */
  286. #endif
  287. #ifndef CONFIG_SMP
  288. #define CONFIG_SMP
  289. #endif
  290. C_MODE_START
  291. #include <asm/atomic.h>
  292. C_MODE_END
  293. #endif
  294. #include <errno.h>                /* Recommended by debian */
  295. /* We need the following to go around a problem with openssl on solaris */
  296. #if defined(HAVE_CRYPT_H)
  297. #include <crypt.h>
  298. #endif
  299.  
  300. /*
  301.   A lot of our programs uses asserts, so better to always include it
  302.   This also fixes a problem when people uses DBUG_ASSERT without including
  303.   assert.h
  304. */
  305. #include <assert.h>
  306.  
  307. /* Go around some bugs in different OS and compilers */
  308. #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
  309. #include <sys/stream.h>        /* HPUX 10.20 defines ulong here. UGLY !!! */
  310. #define HAVE_ULONG
  311. #endif
  312. #ifdef DONT_USE_FINITE        /* HPUX 11.x has is_finite() */
  313. #undef HAVE_FINITE
  314. #endif
  315. #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD)
  316. /* Fix bug in setrlimit */
  317. #undef setrlimit
  318. #define setrlimit cma_setrlimit64
  319. #endif
  320.  
  321. #ifdef __QNXNTO__
  322. /* This has to be after include limits.h */
  323. #define HAVE_ERRNO_AS_DEFINE
  324. #define HAVE_FCNTL_LOCK
  325. #undef  HAVE_FINITE
  326. #undef  LONGLONG_MIN            /* These get wrongly defined in QNX 6.2 */
  327. #undef  LONGLONG_MAX            /* standard system library 'limits.h' */
  328. #endif
  329.  
  330. /* We can not live without the following defines */
  331.  
  332. #define USE_MYFUNC 1        /* Must use syscall indirection */
  333. #define MASTER 1        /* Compile without unireg */
  334. #define ENGLISH 1        /* Messages in English */
  335. #define POSIX_MISTAKE 1        /* regexp: Fix stupid spec error */
  336. #define USE_REGEX 1        /* We want the use the regex library */
  337. /* Do not define for ultra sparcs */
  338. #ifndef OS2
  339. #define USE_BMOVE512 1        /* Use this unless system bmove is faster */
  340. #endif
  341.  
  342. #define QUOTE_ARG(x)        #x    /* Quote argument (before cpp) */
  343. #define STRINGIFY_ARG(x) QUOTE_ARG(x)    /* Quote argument, after cpp */
  344.  
  345. /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
  346. #ifdef I_AM_PARANOID
  347. #define DONT_ALLOW_USER_CHANGE 1
  348. #define DONT_USE_MYSQL_PWD 1
  349. #endif
  350.  
  351. /* Does the system remember a signal handler after a signal ? */
  352. #ifndef HAVE_BSD_SIGNALS
  353. #define DONT_REMEMBER_SIGNAL
  354. #endif
  355.  
  356. /* Define void to stop lint from generating "null effekt" comments */
  357. #ifndef DONT_DEFINE_VOID
  358. #ifdef _lint
  359. int    __void__;
  360. #define VOID(X)        (__void__ = (int) (X))
  361. #else
  362. #undef VOID
  363. #define VOID(X)        (X)
  364. #endif
  365. #endif /* DONT_DEFINE_VOID */
  366.  
  367. #if defined(_lint) || defined(FORCE_INIT_OF_VARS)
  368. #define LINT_INIT(var)    var=0            /* No uninitialize-warning */
  369. #else
  370. #define LINT_INIT(var)
  371. #endif
  372.  
  373. /* Define some useful general macros */
  374. #if defined(__cplusplus) && defined(__GNUC__)
  375. #define max(a, b)    ((a) >? (b))
  376. #define min(a, b)    ((a) <? (b))
  377. #elif !defined(max)
  378. #define max(a, b)    ((a) > (b) ? (a) : (b))
  379. #define min(a, b)    ((a) < (b) ? (a) : (b))
  380. #endif
  381.  
  382. #if defined(__EMX__) || !defined(HAVE_UINT)
  383. typedef unsigned int uint;
  384. typedef unsigned short ushort;
  385. #endif
  386.  
  387. #define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
  388. #define sgn(a)        (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
  389. #define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
  390. #define test(a)        ((a) ? 1 : 0)
  391. #define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
  392. #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
  393. #define test_all_bits(a,b) (((a) & (b)) == (b))
  394. #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
  395. #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
  396. #ifndef HAVE_RINT
  397. #define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
  398. #endif
  399.  
  400. /* Define some general constants */
  401. #ifndef TRUE
  402. #define TRUE        (1)    /* Logical true */
  403. #define FALSE        (0)    /* Logical false */
  404. #endif
  405.  
  406. #if defined(__GNUC__)
  407. #define function_volatile    volatile
  408. #define my_reinterpret_cast(A) reinterpret_cast<A>
  409. #define my_const_cast(A) const_cast<A>
  410. #elif !defined(my_reinterpret_cast)
  411. #define my_reinterpret_cast(A) (A)
  412. #define my_const_cast(A) (A)
  413. #endif
  414. #if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__)  || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
  415. #define __attribute__(A)
  416. #endif
  417.  
  418. /* From old s-system.h */
  419.  
  420. /*
  421.   Support macros for non ansi & other old compilers. Since such
  422.   things are no longer supported we do nothing. We keep then since
  423.   some of our code may still be needed to upgrade old customers.
  424. */
  425. #define _VARARGS(X) X
  426. #define _STATIC_VARARGS(X) X
  427. #define _PC(X)    X
  428.  
  429. #if defined(DBUG_ON) && defined(DBUG_OFF)
  430. #undef DBUG_OFF
  431. #endif
  432.  
  433. #if defined(_lint) && !defined(DBUG_OFF)
  434. #define DBUG_OFF
  435. #endif
  436.  
  437. #include <my_dbug.h>
  438.  
  439. #define MIN_ARRAY_SIZE    0    /* Zero or One. Gcc allows zero*/
  440. #define ASCII_BITS_USED 8    /* Bit char used */
  441. #define NEAR_F            /* No near function handling */
  442.  
  443. /* Some types that is different between systems */
  444.  
  445. typedef int    File;        /* File descriptor */
  446. #ifndef Socket_defined
  447. typedef int    my_socket;    /* File descriptor for sockets */
  448. #define INVALID_SOCKET -1
  449. #endif
  450. /* Type for fuctions that handles signals */
  451. #define sig_handler RETSIGTYPE
  452. C_MODE_START
  453. typedef void    (*sig_return)();/* Returns type from signal */
  454. C_MODE_END
  455. #if defined(__GNUC__) && !defined(_lint)
  456. typedef char    pchar;        /* Mixed prototypes can take char */
  457. typedef char    puchar;        /* Mixed prototypes can take char */
  458. typedef char    pbool;        /* Mixed prototypes can take char */
  459. typedef short    pshort;        /* Mixed prototypes can take short int */
  460. typedef float    pfloat;        /* Mixed prototypes can take float */
  461. #else
  462. typedef int    pchar;        /* Mixed prototypes can't take char */
  463. typedef uint    puchar;        /* Mixed prototypes can't take char */
  464. typedef int    pbool;        /* Mixed prototypes can't take char */
  465. typedef int    pshort;        /* Mixed prototypes can't take short int */
  466. typedef double    pfloat;        /* Mixed prototypes can't take float */
  467. #endif
  468. C_MODE_START
  469. typedef int    (*qsort_cmp)(const void *,const void *);
  470. typedef int    (*qsort_cmp2)(void*, const void *,const void *);
  471. C_MODE_END
  472. #ifdef HAVE_mit_thread
  473. #define qsort_t void
  474. #undef QSORT_TYPE_IS_VOID
  475. #define QSORT_TYPE_IS_VOID
  476. #else
  477. #define qsort_t RETQSORTTYPE    /* Broken GCC cant handle typedef !!!! */
  478. #endif
  479. #ifdef HAVE_mit_thread
  480. #define size_socket socklen_t    /* Type of last arg to accept */
  481. #else
  482. #ifdef HAVE_SYS_SOCKET_H
  483. #include <sys/socket.h>
  484. #endif
  485. typedef SOCKET_SIZE_TYPE size_socket;
  486. #endif
  487.  
  488. #ifndef SOCKOPT_OPTLEN_TYPE
  489. #define SOCKOPT_OPTLEN_TYPE size_socket
  490. #endif
  491.  
  492. /* file create flags */
  493.  
  494. #ifndef O_SHARE            /* Probably not windows */
  495. #define O_SHARE        0    /* Flag to my_open for shared files */
  496. #ifndef O_BINARY
  497. #define O_BINARY    0    /* Flag to my_open for binary files */
  498. #endif
  499. #ifndef FILE_BINARY
  500. #define FILE_BINARY    O_BINARY /* Flag to my_fopen for binary streams */
  501. #endif
  502. #ifdef HAVE_FCNTL
  503. #define HAVE_FCNTL_LOCK
  504. #define F_TO_EOF    0L    /* Param to lockf() to lock rest of file */
  505. #endif
  506. #endif /* O_SHARE */
  507.  
  508. #ifndef O_TEMPORARY
  509. #define O_TEMPORARY    0
  510. #endif
  511. #ifndef O_SHORT_LIVED
  512. #define O_SHORT_LIVED    0
  513. #endif
  514.  
  515. /* #define USE_RECORD_LOCK    */
  516.  
  517.     /* Unsigned types supported by the compiler */
  518. #define UNSINT8            /* unsigned int8 (char) */
  519. #define UNSINT16        /* unsigned int16 */
  520. #define UNSINT32        /* unsigned int32 */
  521.  
  522.     /* General constants */
  523. #define SC_MAXWIDTH    256    /* Max width of screen (for error messages) */
  524. #define FN_LEN        256    /* Max file name len */
  525. #define FN_HEADLEN    253    /* Max length of filepart of file name */
  526. #define FN_EXTLEN    20    /* Max length of extension (part of FN_LEN) */
  527. #define FN_REFLEN    512    /* Max length of full path-name */
  528. #define FN_EXTCHAR    '.'
  529. #define FN_HOMELIB    '~'    /* ~/ is used as abbrev for home dir */
  530. #define FN_CURLIB    '.'    /* ./ is used as abbrev for current dir */
  531. #define FN_PARENTDIR    ".."    /* Parent directory; Must be a string */
  532. #define FN_DEVCHAR    ':'
  533.  
  534. #ifndef FN_LIBCHAR
  535. #ifdef __EMX__
  536. #define FN_LIBCHAR    '\\'
  537. #define FN_ROOTDIR    "\\"
  538. #else
  539. #define FN_LIBCHAR    '/'
  540. #define FN_ROOTDIR    "/"
  541. #endif
  542. #endif
  543. #define MY_NFILE    64    /* This is only used to save filenames */
  544. #ifndef OS_FILE_LIMIT
  545. #define OS_FILE_LIMIT    65535
  546. #endif
  547.  
  548. /* #define EXT_IN_LIBNAME     */
  549. /* #define FN_NO_CASE_SENCE   */
  550. /* #define FN_UPPER_CASE TRUE */
  551.  
  552. /*
  553.   Io buffer size; Must be a power of 2 and a multiple of 512. May be
  554.   smaller what the disk page size. This influences the speed of the
  555.   isam btree library. eg to big to slow.
  556. */
  557. #define IO_SIZE            4096
  558. /*
  559.   How much overhead does malloc have. The code often allocates
  560.   something like 1024-MALLOC_OVERHEAD bytes
  561. */
  562. #ifdef SAFEMALLOC
  563. #define MALLOC_OVERHEAD (8+24+4)
  564. #else
  565. #define MALLOC_OVERHEAD 8
  566. #endif
  567.     /* get memory in huncs */
  568. #define ONCE_ALLOC_INIT        (uint) (4096-MALLOC_OVERHEAD)
  569.     /* Typical record cash */
  570. #define RECORD_CACHE_SIZE    (uint) (64*1024-MALLOC_OVERHEAD)
  571.     /* Typical key cash */
  572. #define KEY_CACHE_SIZE        (uint) (8*1024*1024-MALLOC_OVERHEAD)
  573.     /* Default size of a key cache block  */
  574. #define KEY_CACHE_BLOCK_SIZE    (uint) 1024
  575.  
  576.  
  577.     /* Some things that this system doesn't have */
  578.  
  579. #define NO_HASH            /* Not needed anymore */
  580. #ifdef __WIN__
  581. #define NO_DIR_LIBRARY        /* Not standar dir-library */
  582. #define USE_MY_STAT_STRUCT    /* For my_lib */
  583. #endif
  584.  
  585. /* Some defines of functions for portability */
  586.  
  587. #undef remove        /* Crashes MySQL on SCO 5.0.0 */
  588. #ifndef __WIN__
  589. #ifdef OS2
  590. #define closesocket(A)    soclose(A)
  591. #else
  592. #define closesocket(A)    close(A)
  593. #endif
  594. #ifndef ulonglong2double
  595. #define ulonglong2double(A) ((double) (ulonglong) (A))
  596. #define my_off_t2double(A)  ((double) (my_off_t) (A))
  597. #endif
  598. #endif
  599.  
  600. #ifndef offsetof
  601. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  602. #endif
  603. #define ulong_to_double(X) ((double) (ulong) (X))
  604. #define SET_STACK_SIZE(X)    /* Not needed on real machines */
  605.  
  606. #if !defined(HAVE_mit_thread) && !defined(HAVE_STRTOK_R)
  607. #define strtok_r(A,B,C) strtok((A),(B))
  608. #endif
  609.  
  610. /* Remove some things that mit_thread break or doesn't support */
  611. #if defined(HAVE_mit_thread) && defined(THREAD)
  612. #undef HAVE_PREAD
  613. #undef HAVE_REALPATH
  614. #undef HAVE_MLOCK
  615. #undef HAVE_TEMPNAM                /* Use ours */
  616. #undef HAVE_PTHREAD_SETPRIO
  617. #undef HAVE_FTRUNCATE
  618. #undef HAVE_READLINK
  619. #endif
  620.  
  621. /* This is from the old m-machine.h file */
  622.  
  623. #if SIZEOF_LONG_LONG > 4
  624. #define HAVE_LONG_LONG 1
  625. #endif
  626.  
  627. /*
  628.   Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
  629.   ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
  630.   Also on Windows we define these constants by hand in config-win.h.
  631. */
  632.  
  633. #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
  634. #define LONGLONG_MIN    ((long long) 0x8000000000000000LL)
  635. #define LONGLONG_MAX    ((long long) 0x7FFFFFFFFFFFFFFFLL)
  636. #endif
  637.  
  638. #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
  639. /* First check for ANSI C99 definition: */
  640. #ifdef ULLONG_MAX
  641. #define ULONGLONG_MAX  ULLONG_MAX
  642. #else
  643. #define ULONGLONG_MAX ((unsigned long long)(~0ULL))
  644. #endif
  645. #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
  646.  
  647. #if SIZEOF_LONG == 4
  648. #define INT_MIN32    (long) 0x80000000L
  649. #define INT_MAX32    (long) 0x7FFFFFFFL
  650. #define INT_MIN24    ((long) 0xff800000L)
  651. #define INT_MAX24    0x007fffffL
  652. #define INT_MIN16    ((short int) 0x8000)
  653. #define INT_MAX16    0x7FFF
  654. #define INT_MIN8    ((char) 0x80)
  655. #define INT_MAX8    ((char) 0x7F)
  656. #else  /* Probably Alpha */
  657. #define INT_MIN32    ((long) (int) 0x80000000)
  658. #define INT_MAX32    ((long) (int) 0x7FFFFFFF)
  659. #define INT_MIN24    ((long) (int) 0xff800000)
  660. #define INT_MAX24    ((long) (int) 0x007fffff)
  661. #define INT_MIN16    ((short int) 0xffff8000)
  662. #define INT_MAX16    ((short int) 0x00007FFF)
  663. #endif
  664.  
  665. /* From limits.h instead */
  666. #ifndef DBL_MIN
  667. #define DBL_MIN        4.94065645841246544e-324
  668. #define FLT_MIN        ((float)1.40129846432481707e-45)
  669. #endif
  670. #ifndef DBL_MAX
  671. #define DBL_MAX        1.79769313486231470e+308
  672. #define FLT_MAX        ((float)3.40282346638528860e+38)
  673. #endif
  674.  
  675. #if !defined(HAVE_ISINF) && !defined(isinf)
  676. #define isinf(X)    0
  677. #endif
  678.  
  679. /* Define missing math constants. */
  680. #ifndef M_PI
  681. #define M_PI 3.14159265358979323846
  682. #endif
  683. #ifndef M_E
  684. #define M_E 2.7182818284590452354
  685. #endif
  686. #ifndef M_LN2
  687. #define M_LN2 0.69314718055994530942
  688. #endif
  689.  
  690. /*
  691.   Max size that must be added to a so that we know Size to make
  692.   adressable obj.
  693. */
  694. #if SIZEOF_CHARP == 4
  695. typedef long        my_ptrdiff_t;
  696. #else
  697. typedef long long    my_ptrdiff_t;
  698. #endif
  699.  
  700. #define MY_ALIGN(A,L)    (((A) + (L) - 1) & ~((L) - 1))
  701. #define ALIGN_SIZE(A)    MY_ALIGN((A),sizeof(double))
  702. /* Size to make adressable obj. */
  703. #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
  704.              /* Offset of field f in structure t */
  705. #define OFFSET(t, f)    ((size_t)(char *)&((t *)0)->f)
  706. #define ADD_TO_PTR(ptr,size,type) (type) ((byte*) (ptr)+size)
  707. #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((byte*) (A) - (byte*) (B))
  708.  
  709. #define NullS        (char *) 0
  710. /* Nowdays we do not support MessyDos */
  711. #ifndef NEAR
  712. #define NEAR                /* Who needs segments ? */
  713. #define FAR                /* On a good machine */
  714. #ifndef HUGE_PTR
  715. #define HUGE_PTR
  716. #endif
  717. #endif
  718. #if defined(__IBMC__) || defined(__IBMCPP__)
  719. /* This was  _System _Export but caused a lot of warnings on _AIX43 */
  720. #define STDCALL
  721. #elif !defined( STDCALL)
  722. #define STDCALL
  723. #endif
  724.  
  725. /* Typdefs for easyier portability */
  726.  
  727. #if defined(VOIDTYPE)
  728. typedef void    *gptr;        /* Generic pointer */
  729. #else
  730. typedef char    *gptr;        /* Generic pointer */
  731. #endif
  732. #ifndef HAVE_INT_8_16_32
  733. typedef char    int8;        /* Signed integer >= 8    bits */
  734. typedef short    int16;        /* Signed integer >= 16 bits */
  735. #endif
  736. #ifndef HAVE_UCHAR
  737. typedef unsigned char    uchar;    /* Short for unsigned char */
  738. #endif
  739. typedef unsigned char    uint8;    /* Short for unsigned integer >= 8  bits */
  740. typedef unsigned short    uint16; /* Short for unsigned integer >= 16 bits */
  741.  
  742. #if SIZEOF_INT == 4
  743. #ifndef HAVE_INT_8_16_32
  744. typedef int        int32;
  745. #endif
  746. typedef unsigned int    uint32; /* Short for unsigned integer >= 32 bits */
  747. #elif SIZEOF_LONG == 4
  748. #ifndef HAVE_INT_8_16_32
  749. typedef long        int32;
  750. #endif
  751. typedef unsigned long    uint32; /* Short for unsigned integer >= 32 bits */
  752. #else
  753. error "Neither int or long is of 4 bytes width"
  754. #endif
  755.  
  756. #if !defined(HAVE_ULONG) && !defined(HAVE_LINUXTHREADS) && !defined(__USE_MISC)
  757. typedef unsigned long    ulong;          /* Short for unsigned long */
  758. #endif
  759. #ifndef longlong_defined
  760. #if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8
  761. typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
  762. typedef long long int    longlong;
  763. #else
  764. typedef unsigned long    ulonglong;      /* ulong or unsigned long long */
  765. typedef long        longlong;
  766. #endif
  767. #endif
  768.  
  769. #if defined(NO_CLIENT_LONG_LONG)
  770. typedef unsigned long my_ulonglong;
  771. #elif defined (__WIN__)
  772. typedef unsigned __int64 my_ulonglong;
  773. #else
  774. typedef unsigned long long my_ulonglong;
  775. #endif
  776.  
  777. #ifdef USE_RAID
  778. /*
  779.   The following is done with a if to not get problems with pre-processors
  780.   with late define evaluation
  781. */
  782. #if SIZEOF_OFF_T == 4
  783. #define SYSTEM_SIZEOF_OFF_T 4
  784. #else
  785. #define SYSTEM_SIZEOF_OFF_T 8
  786. #endif
  787. #undef  SIZEOF_OFF_T
  788. #define SIZEOF_OFF_T        8
  789. #else
  790. #define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
  791. #endif /* USE_RAID */
  792.  
  793. #if SIZEOF_OFF_T > 4
  794. typedef ulonglong my_off_t;
  795. #else
  796. typedef unsigned long my_off_t;
  797. #endif
  798. #define MY_FILEPOS_ERROR    (~(my_off_t) 0)
  799. #if !defined(__WIN__) && !defined(OS2)
  800. typedef off_t os_off_t;
  801. #endif
  802.  
  803. #if defined(__WIN__)
  804. #define socket_errno    WSAGetLastError()
  805. #define SOCKET_EINTR    WSAEINTR
  806. #define SOCKET_EAGAIN    WSAEINPROGRESS
  807. #define SOCKET_EWOULDBLOCK WSAEINPROGRESS
  808. #define SOCKET_ENFILE    ENFILE
  809. #define SOCKET_EMFILE    EMFILE
  810. #elif defined(OS2)
  811. #define socket_errno    sock_errno()
  812. #define SOCKET_EINTR    SOCEINTR
  813. #define SOCKET_EAGAIN    SOCEINPROGRESS
  814. #define SOCKET_EWOULDBLOCK SOCEWOULDBLOCK
  815. #define SOCKET_ENFILE    SOCENFILE
  816. #define SOCKET_EMFILE    SOCEMFILE
  817. #define closesocket(A)    soclose(A)
  818. #else /* Unix */
  819. #define socket_errno    errno
  820. #define closesocket(A)    close(A)
  821. #define SOCKET_EINTR    EINTR
  822. #define SOCKET_EAGAIN    EAGAIN
  823. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  824. #define SOCKET_ENFILE    ENFILE
  825. #define SOCKET_EMFILE    EMFILE
  826. #endif
  827.  
  828. typedef uint8        int7;    /* Most effective integer 0 <= x <= 127 */
  829. typedef short        int15;    /* Most effective integer 0 <= x <= 32767 */
  830. typedef char        *my_string; /* String of characters */
  831. typedef unsigned long    size_s; /* Size of strings (In string-funcs) */
  832. typedef int        myf;    /* Type of MyFlags in my_funcs */
  833. #ifndef byte_defined
  834. typedef char        byte;    /* Smallest addressable unit */
  835. #endif
  836. typedef char        my_bool; /* Small bool */
  837. #if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
  838. typedef char        bool;    /* Ordinary boolean values 0 1 */
  839. #endif
  840.     /* Macros for converting *constants* to the right type */
  841. #define INT8(v)        (int8) (v)
  842. #define INT16(v)    (int16) (v)
  843. #define INT32(v)    (int32) (v)
  844. #define MYF(v)        (myf) (v)
  845.  
  846. #ifndef LL
  847. #ifdef HAVE_LONG_LONG
  848. #define LL(A) A ## LL
  849. #else
  850. #define LL(A) A ## L
  851. #endif
  852. #endif
  853.  
  854. #ifndef ULL
  855. #ifdef HAVE_LONG_LONG
  856. #define ULL(A) A ## ULL
  857. #else
  858. #define ULL(A) A ## UL
  859. #endif
  860. #endif
  861.  
  862. /*
  863.   Defines to make it possible to prioritize register assignments. No
  864.   longer that important with modern compilers.
  865. */
  866. #ifndef USING_X
  867. #define reg1 register
  868. #define reg2 register
  869. #define reg3 register
  870. #define reg4 register
  871. #define reg5 register
  872. #define reg6 register
  873. #define reg7 register
  874. #define reg8 register
  875. #define reg9 register
  876. #define reg10 register
  877. #define reg11 register
  878. #define reg12 register
  879. #define reg13 register
  880. #define reg14 register
  881. #define reg15 register
  882. #define reg16 register
  883. #endif
  884.  
  885. /*
  886.   Sometimes we want to make sure that the variable is not put into
  887.   a register in debugging mode so we can see its value in the core
  888. */
  889.  
  890. #ifndef DBUG_OFF
  891. #define dbug_volatile volatile
  892. #else
  893. #define dbug_volatile
  894. #endif
  895.  
  896. /* Defines for time function */
  897. #define SCALE_SEC    100
  898. #define SCALE_USEC    10000
  899. #define MY_HOW_OFTEN_TO_ALARM    2    /* How often we want info on screen */
  900. #define MY_HOW_OFTEN_TO_WRITE    1000    /* How often we want info on screen */
  901.  
  902. #ifndef set_timespec
  903. #ifdef HAVE_TIMESPEC_TS_SEC
  904. #define set_timespec(ABSTIME,SEC) { (ABSTIME).ts_sec=time(0) + (time_t) (SEC); (ABSTIME).ts_nsec=0; }
  905. #else
  906. #define set_timespec(ABSTIME,SEC) \
  907. {\
  908.   struct timeval tv;\
  909.   gettimeofday(&tv,0);\
  910.   (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
  911.   (ABSTIME).tv_nsec=tv.tv_usec*1000;\
  912. }
  913. #endif /* HAVE_TIMESPEC_TS_SEC */
  914. #endif /* set_timespec */
  915.  
  916. /*
  917.   Define-funktions for reading and storing in machine independent format
  918.   (low byte first)
  919. */
  920.  
  921. /* Optimized store functions for Intel x86 */
  922. #if defined(__i386__) && !defined(_WIN64)
  923. #define sint2korr(A)    (*((int16 *) (A)))
  924. #define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \
  925.                   (((uint32) 255L << 24) | \
  926.                    (((uint32) (uchar) (A)[2]) << 16) |\
  927.                    (((uint32) (uchar) (A)[1]) << 8) | \
  928.                    ((uint32) (uchar) (A)[0])) : \
  929.                   (((uint32) (uchar) (A)[2]) << 16) |\
  930.                   (((uint32) (uchar) (A)[1]) << 8) | \
  931.                   ((uint32) (uchar) (A)[0])))
  932. #define sint4korr(A)    (*((long *) (A)))
  933. #define uint2korr(A)    (*((uint16 *) (A)))
  934. #ifdef HAVE_purify
  935. #define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
  936.                   (((uint32) ((uchar) (A)[1])) << 8) +\
  937.                   (((uint32) ((uchar) (A)[2])) << 16))
  938. #else
  939. #define uint3korr(A)    (long) (*((unsigned long *) (A)) & 0xFFFFFF)
  940. #endif
  941. #define uint4korr(A)    (*((unsigned long *) (A)))
  942. #define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  943.                     (((uint32) ((uchar) (A)[1])) << 8) +\
  944.                     (((uint32) ((uchar) (A)[2])) << 16) +\
  945.                     (((uint32) ((uchar) (A)[3])) << 24)) +\
  946.                     (((ulonglong) ((uchar) (A)[4])) << 32))
  947. #define uint8korr(A)    (*((ulonglong *) (A)))
  948. #define sint8korr(A)    (*((longlong *) (A)))
  949. #define int2store(T,A)    *((uint16*) (T))= (uint16) (A)
  950. #define int3store(T,A)  do { *(T)=  (uchar) ((A));\
  951.                             *(T+1)=(uchar) (((uint) (A) >> 8));\
  952.                             *(T+2)=(uchar) (((A) >> 16)); } while (0)
  953. #define int4store(T,A)    *((long *) (T))= (long) (A)
  954. #define int5store(T,A)  do { *(T)= (uchar)((A));\
  955.                              *((T)+1)=(uchar) (((A) >> 8));\
  956.                              *((T)+2)=(uchar) (((A) >> 16));\
  957.                              *((T)+3)=(uchar) (((A) >> 24)); \
  958.                              *((T)+4)=(uchar) (((A) >> 32)); } while(0)
  959. #define int8store(T,A)    *((ulonglong *) (T))= (ulonglong) (A)
  960.  
  961. typedef union {
  962.   double v;
  963.   long m[2];
  964. } doubleget_union;
  965. #define doubleget(V,M)    \
  966. do { doubleget_union _tmp; \
  967.      _tmp.m[0] = *((long*)(M)); \
  968.      _tmp.m[1] = *(((long*) (M))+1); \
  969.      (V) = _tmp.v; } while(0)
  970. #define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
  971.                  *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
  972.                          } while (0)
  973. #define float4get(V,M) do { *((long *) &(V)) = *((long*) (M)); } while(0)
  974. #define float8get(V,M) doubleget((V),(M))
  975. #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float))
  976. #define floatstore(T,V) memcpy((byte*)(T), (byte*)(&V), sizeof(float))
  977. #define float8store(V,M) doublestore((V),(M))
  978. #endif /* __i386__ */
  979.  
  980. #ifndef sint2korr
  981. /*
  982.   We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
  983.   were done before)
  984. */
  985. #define sint2korr(A)    (int16) (((int16) ((uchar) (A)[0])) +\
  986.                  ((int16) ((int16) (A)[1]) << 8))
  987. #define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \
  988.                   (((uint32) 255L << 24) | \
  989.                    (((uint32) (uchar) (A)[2]) << 16) |\
  990.                    (((uint32) (uchar) (A)[1]) << 8) | \
  991.                    ((uint32) (uchar) (A)[0])) : \
  992.                   (((uint32) (uchar) (A)[2]) << 16) |\
  993.                   (((uint32) (uchar) (A)[1]) << 8) | \
  994.                   ((uint32) (uchar) (A)[0])))
  995. #define sint4korr(A)    (int32) (((int32) ((uchar) (A)[0])) +\
  996.                 (((int32) ((uchar) (A)[1]) << 8)) +\
  997.                 (((int32) ((uchar) (A)[2]) << 16)) +\
  998.                 (((int32) ((int16) (A)[3]) << 24)))
  999. #define sint8korr(A)    (longlong) uint8korr(A)
  1000. #define uint2korr(A)    (uint16) (((uint16) ((uchar) (A)[0])) +\
  1001.                   ((uint16) ((uchar) (A)[1]) << 8))
  1002. #define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
  1003.                   (((uint32) ((uchar) (A)[1])) << 8) +\
  1004.                   (((uint32) ((uchar) (A)[2])) << 16))
  1005. #define uint4korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
  1006.                   (((uint32) ((uchar) (A)[1])) << 8) +\
  1007.                   (((uint32) ((uchar) (A)[2])) << 16) +\
  1008.                   (((uint32) ((uchar) (A)[3])) << 24))
  1009. #define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  1010.                     (((uint32) ((uchar) (A)[1])) << 8) +\
  1011.                     (((uint32) ((uchar) (A)[2])) << 16) +\
  1012.                     (((uint32) ((uchar) (A)[3])) << 24)) +\
  1013.                     (((ulonglong) ((uchar) (A)[4])) << 32))
  1014. #define uint8korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  1015.                     (((uint32) ((uchar) (A)[1])) << 8) +\
  1016.                     (((uint32) ((uchar) (A)[2])) << 16) +\
  1017.                     (((uint32) ((uchar) (A)[3])) << 24)) +\
  1018.             (((ulonglong) (((uint32) ((uchar) (A)[4])) +\
  1019.                     (((uint32) ((uchar) (A)[5])) << 8) +\
  1020.                     (((uint32) ((uchar) (A)[6])) << 16) +\
  1021.                     (((uint32) ((uchar) (A)[7])) << 24))) <<\
  1022.                     32))
  1023. #define int2store(T,A)       do { uint def_temp= (uint) (A) ;\
  1024.                                   *((uchar*) (T))=  (uchar)(def_temp); \
  1025.                                    *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
  1026.                              } while(0)
  1027. #define int3store(T,A)       do { /*lint -save -e734 */\
  1028.                                   *((uchar*)(T))=(uchar) ((A));\
  1029.                                   *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
  1030.                                   *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
  1031.                                   /*lint -restore */} while(0)
  1032. #define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
  1033.                                   *(((char *)(T))+1)=(char) (((A) >> 8));\
  1034.                                   *(((char *)(T))+2)=(char) (((A) >> 16));\
  1035.                                   *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
  1036. #define int5store(T,A)       do { *((char *)(T))=((A));\
  1037.                                   *(((char *)(T))+1)=(((A) >> 8));\
  1038.                                   *(((char *)(T))+2)=(((A) >> 16));\
  1039.                                   *(((char *)(T))+3)=(((A) >> 24)); \
  1040.                                   *(((char *)(T))+4)=(((A) >> 32)); } while(0)
  1041. #define int8store(T,A)       do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
  1042.                                   int4store((T),def_temp); \
  1043.                                   int4store((T+4),def_temp2); } while(0)
  1044. #ifdef WORDS_BIGENDIAN
  1045. #define float4store(T,A) do { *(T)= ((byte *) &A)[3];\
  1046.                               *((T)+1)=(char) ((byte *) &A)[2];\
  1047.                               *((T)+2)=(char) ((byte *) &A)[1];\
  1048.                               *((T)+3)=(char) ((byte *) &A)[0]; } while(0)
  1049.  
  1050. #define float4get(V,M)   do { float def_temp;\
  1051.                               ((byte*) &def_temp)[0]=(M)[3];\
  1052.                               ((byte*) &def_temp)[1]=(M)[2];\
  1053.                               ((byte*) &def_temp)[2]=(M)[1];\
  1054.                               ((byte*) &def_temp)[3]=(M)[0];\
  1055.                               (V)=def_temp; } while(0)
  1056. #define float8store(T,V) do { *(T)= ((byte *) &V)[7];\
  1057.                               *((T)+1)=(char) ((byte *) &V)[6];\
  1058.                               *((T)+2)=(char) ((byte *) &V)[5];\
  1059.                               *((T)+3)=(char) ((byte *) &V)[4];\
  1060.                               *((T)+4)=(char) ((byte *) &V)[3];\
  1061.                               *((T)+5)=(char) ((byte *) &V)[2];\
  1062.                               *((T)+6)=(char) ((byte *) &V)[1];\
  1063.                               *((T)+7)=(char) ((byte *) &V)[0]; } while(0)
  1064.  
  1065. #define float8get(V,M)   do { double def_temp;\
  1066.                               ((byte*) &def_temp)[0]=(M)[7];\
  1067.                               ((byte*) &def_temp)[1]=(M)[6];\
  1068.                               ((byte*) &def_temp)[2]=(M)[5];\
  1069.                               ((byte*) &def_temp)[3]=(M)[4];\
  1070.                               ((byte*) &def_temp)[4]=(M)[3];\
  1071.                               ((byte*) &def_temp)[5]=(M)[2];\
  1072.                               ((byte*) &def_temp)[6]=(M)[1];\
  1073.                               ((byte*) &def_temp)[7]=(M)[0];\
  1074.                               (V) = def_temp; } while(0)
  1075. #else
  1076. #define float4get(V,M)   memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float))
  1077. #define float4store(V,M) memcpy_fixed((byte*) V,(byte*) (&M),sizeof(float))
  1078.  
  1079. #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
  1080. #define doublestore(T,V) do { *(T)= ((byte *) &V)[4];\
  1081.                               *(((char*)T)+1)=(char) ((byte *) &V)[5];\
  1082.                               *(((char*)T)+2)=(char) ((byte *) &V)[6];\
  1083.                               *(((char*)T)+3)=(char) ((byte *) &V)[7];\
  1084.                               *(((char*)T)+4)=(char) ((byte *) &V)[0];\
  1085.                               *(((char*)T)+5)=(char) ((byte *) &V)[1];\
  1086.                               *(((char*)T)+6)=(char) ((byte *) &V)[2];\
  1087.                               *(((char*)T)+7)=(char) ((byte *) &V)[3]; }\
  1088.                          while(0)
  1089. #define doubleget(V,M)   do { double def_temp;\
  1090.                               ((byte*) &def_temp)[0]=(M)[4];\
  1091.                               ((byte*) &def_temp)[1]=(M)[5];\
  1092.                               ((byte*) &def_temp)[2]=(M)[6];\
  1093.                               ((byte*) &def_temp)[3]=(M)[7];\
  1094.                               ((byte*) &def_temp)[4]=(M)[0];\
  1095.                               ((byte*) &def_temp)[5]=(M)[1];\
  1096.                               ((byte*) &def_temp)[6]=(M)[2];\
  1097.                               ((byte*) &def_temp)[7]=(M)[3];\
  1098.                               (V) = def_temp; } while(0)
  1099. #endif /* __FLOAT_WORD_ORDER */
  1100.  
  1101. #define float8get(V,M)   doubleget((V),(M))
  1102. #define float8store(V,M) doublestore((V),(M))
  1103. #endif /* WORDS_BIGENDIAN */
  1104.  
  1105. #endif /* sint2korr */
  1106.  
  1107. /*
  1108.   Macro for reading 32-bit integer from network byte order (big-endian)
  1109.   from unaligned memory location.
  1110. */
  1111. #define int4net(A)        (int32) (((uint32) ((uchar) (A)[3]))        |\
  1112.                   (((uint32) ((uchar) (A)[2])) << 8)  |\
  1113.                   (((uint32) ((uchar) (A)[1])) << 16) |\
  1114.                   (((uint32) ((uchar) (A)[0])) << 24))
  1115. /*
  1116.   Define-funktions for reading and storing in machine format from/to
  1117.   short/long to/from some place in memory V should be a (not
  1118.   register) variable, M is a pointer to byte
  1119. */
  1120.  
  1121. #ifdef WORDS_BIGENDIAN
  1122.  
  1123. #define ushortget(V,M)  do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
  1124.                                  ((uint16) ((uint16) (M)[0]) << 8)); } while(0)
  1125. #define shortget(V,M)   do { V = (short) (((short) ((uchar) (M)[1]))+\
  1126.                                  ((short) ((short) (M)[0]) << 8)); } while(0)
  1127. #define longget(V,M)    do { int32 def_temp;\
  1128.                              ((byte*) &def_temp)[0]=(M)[0];\
  1129.                              ((byte*) &def_temp)[1]=(M)[1];\
  1130.                              ((byte*) &def_temp)[2]=(M)[2];\
  1131.                              ((byte*) &def_temp)[3]=(M)[3];\
  1132.                              (V)=def_temp; } while(0)
  1133. #define ulongget(V,M)   do { uint32 def_temp;\
  1134.                             ((byte*) &def_temp)[0]=(M)[0];\
  1135.                             ((byte*) &def_temp)[1]=(M)[1];\
  1136.                             ((byte*) &def_temp)[2]=(M)[2];\
  1137.                             ((byte*) &def_temp)[3]=(M)[3];\
  1138.                             (V)=def_temp; } while(0)
  1139. #define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
  1140.                              *(((char*)T)+1)=(char)(def_temp); \
  1141.                              *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
  1142. #define longstore(T,A)  do { *(((char*)T)+3)=((A));\
  1143.                              *(((char*)T)+2)=(((A) >> 8));\
  1144.                              *(((char*)T)+1)=(((A) >> 16));\
  1145.                              *(((char*)T)+0)=(((A) >> 24)); } while(0)
  1146.  
  1147. #define floatstore(T,V) memcpy_fixed((byte*)(T), (byte*)(&V), sizeof(float))
  1148. #define doubleget(V,M)     memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double))
  1149. #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double))
  1150. #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong))
  1151. #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong))
  1152.  
  1153. #else
  1154.  
  1155. #define ushortget(V,M)    do { V = uint2korr(M); } while(0)
  1156. #define shortget(V,M)    do { V = sint2korr(M); } while(0)
  1157. #define longget(V,M)    do { V = sint4korr(M); } while(0)
  1158. #define ulongget(V,M)   do { V = uint4korr(M); } while(0)
  1159. #define shortstore(T,V) int2store(T,V)
  1160. #define longstore(T,V)    int4store(T,V)
  1161. #ifndef floatstore
  1162. #define floatstore(T,V) memcpy_fixed((byte*)(T), (byte*)(&V), sizeof(float))
  1163. #endif
  1164. #ifndef doubleget
  1165. #define doubleget(V,M)     memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double))
  1166. #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double))
  1167. #endif /* doubleget */
  1168. #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong))
  1169. #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong))
  1170.  
  1171. #endif /* WORDS_BIGENDIAN */
  1172.  
  1173. /* sprintf does not always return the number of bytes :- */
  1174. #ifdef SPRINTF_RETURNS_INT
  1175. #define my_sprintf(buff,args) sprintf args
  1176. #else
  1177. #ifdef SPRINTF_RETURNS_PTR
  1178. #define my_sprintf(buff,args) ((int)(sprintf args - buff))
  1179. #else
  1180. #define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
  1181. #endif
  1182. #endif
  1183.  
  1184. #ifndef THREAD
  1185. #define thread_safe_increment(V,L) (V)++
  1186. #define thread_safe_add(V,C,L)     (V)+=(C)
  1187. #define thread_safe_sub(V,C,L)     (V)-=(C)
  1188. #define statistic_increment(V,L)   (V)++
  1189. #define statistic_add(V,C,L)       (V)+=(C)
  1190. #endif
  1191.  
  1192. #ifdef HAVE_CHARSET_utf8
  1193. #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
  1194. #else
  1195. #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
  1196. #endif
  1197.  
  1198. #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
  1199. #define NO_EMBEDDED_ACCESS_CHECKS
  1200. #endif
  1201.  
  1202. #endif /* my_global_h */
  1203.