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