home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 Autumn / INTERNET109.ISO / pc / software / windows / building / mysql / data1.cab / Development / include / my_global.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-08-03  |  33.8 KB  |  1,109 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. #ifndef CONFIG_SMP
  271. #define CONFIG_SMP
  272. #endif
  273. #include <asm/atomic.h>
  274. #endif
  275. #include <errno.h>                /* Recommended by debian */
  276. /* We need the following to go around a problem with openssl on solaris */
  277. #if defined(HAVE_CRYPT_H)
  278. #include <crypt.h>
  279. #endif
  280.  
  281. /* Go around some bugs in different OS and compilers */
  282. #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
  283. #include <sys/stream.h>        /* HPUX 10.20 defines ulong here. UGLY !!! */
  284. #define HAVE_ULONG
  285. #endif
  286. #ifdef DONT_USE_FINITE        /* HPUX 11.x has is_finite() */
  287. #undef HAVE_FINITE
  288. #endif
  289. #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD)
  290. /* Fix bug in setrlimit */
  291. #undef setrlimit
  292. #define setrlimit cma_setrlimit64
  293. #endif
  294.  
  295. #ifdef __QNXNTO__
  296. /* This has to be after include limits.h */
  297. #define HAVE_ERRNO_AS_DEFINE
  298. #define HAVE_FCNTL_LOCK
  299. #undef  HAVE_FINITE
  300. #undef  LONGLONG_MIN            /* These get wrongly defined in QNX 6.2 */
  301. #undef  LONGLONG_MAX            /* standard system library 'limits.h' */
  302. #endif
  303.  
  304. /* We can not live without the following defines */
  305.  
  306. #define USE_MYFUNC 1        /* Must use syscall indirection */
  307. #define MASTER 1        /* Compile without unireg */
  308. #define ENGLISH 1        /* Messages in English */
  309. #define POSIX_MISTAKE 1        /* regexp: Fix stupid spec error */
  310. #define USE_REGEX 1        /* We want the use the regex library */
  311. /* Do not define for ultra sparcs */
  312. #ifndef OS2
  313. #define USE_BMOVE512 1        /* Use this unless system bmove is faster */
  314. #endif
  315.  
  316. /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
  317. #ifdef I_AM_PARANOID
  318. #define DONT_ALLOW_USER_CHANGE 1
  319. #define DONT_USE_MYSQL_PWD 1
  320. #endif
  321.  
  322. /* Does the system remember a signal handler after a signal ? */
  323. #ifndef HAVE_BSD_SIGNALS
  324. #define DONT_REMEMBER_SIGNAL
  325. #endif
  326.  
  327. /* Define void to stop lint from generating "null effekt" comments */
  328. #ifndef DONT_DEFINE_VOID
  329. #ifdef _lint
  330. int    __void__;
  331. #define VOID(X)        (__void__ = (int) (X))
  332. #else
  333. #undef VOID
  334. #define VOID(X)        (X)
  335. #endif
  336. #endif /* DONT_DEFINE_VOID */
  337.  
  338. #if defined(_lint) || defined(FORCE_INIT_OF_VARS)
  339. #define LINT_INIT(var)    var=0            /* No uninitialize-warning */
  340. #else
  341. #define LINT_INIT(var)
  342. #endif
  343.  
  344. /* Define some useful general macros */
  345. #if defined(__cplusplus) && defined(__GNUC__)
  346. #define max(a, b)    ((a) >? (b))
  347. #define min(a, b)    ((a) <? (b))
  348. #elif !defined(max)
  349. #define max(a, b)    ((a) > (b) ? (a) : (b))
  350. #define min(a, b)    ((a) < (b) ? (a) : (b))
  351. #endif
  352.  
  353. #if defined(__EMX__) || !defined(HAVE_UINT)
  354. typedef unsigned int uint;
  355. typedef unsigned short ushort;
  356. #endif
  357.  
  358. #define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
  359. #define sgn(a)        (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
  360. #define swap(t,a,b)    { register t dummy; dummy = a; a = b; b = dummy; }
  361. #define test(a)        ((a) ? 1 : 0)
  362. #define set_if_bigger(a,b)  { if ((a) < (b)) (a)=(b); }
  363. #define set_if_smaller(a,b) { if ((a) > (b)) (a)=(b); }
  364. #define test_all_bits(a,b) (((a) & (b)) == (b))
  365. #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
  366. #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
  367. #ifndef HAVE_RINT
  368. #define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
  369. #endif
  370.  
  371. /* Define some general constants */
  372. #ifndef TRUE
  373. #define TRUE        (1)    /* Logical true */
  374. #define FALSE        (0)    /* Logical false */
  375. #endif
  376.  
  377. #if defined(__GNUC__)
  378. #define function_volatile    volatile
  379. #define my_reinterpret_cast(A) reinterpret_cast<A>
  380. #define my_const_cast(A) const_cast<A>
  381. #elif !defined(my_reinterpret_cast)
  382. #define my_reinterpret_cast(A) (A)
  383. #define my_const_cast(A) (A)
  384. #endif
  385. #if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__)  || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
  386. #define __attribute__(A)
  387. #endif
  388.  
  389. /* From old s-system.h */
  390.  
  391. /*
  392.   Support macros for non ansi & other old compilers. Since such
  393.   things are no longer supported we do nothing. We keep then since
  394.   some of our code may still be needed to upgrade old customers.
  395. */
  396. #define _VARARGS(X) X
  397. #define _STATIC_VARARGS(X) X
  398. #define _PC(X)    X
  399.  
  400. #if defined(DBUG_ON) && defined(DBUG_OFF)
  401. #undef DBUG_OFF
  402. #endif
  403.  
  404. #if defined(_lint) && !defined(DBUG_OFF)
  405. #define DBUG_OFF
  406. #endif
  407.  
  408. #include <my_dbug.h>
  409.  
  410. #define MIN_ARRAY_SIZE    0    /* Zero or One. Gcc allows zero*/
  411. #define ASCII_BITS_USED 8    /* Bit char used */
  412. #define NEAR_F            /* No near function handling */
  413.  
  414. /* Some types that is different between systems */
  415.  
  416. typedef int    File;        /* File descriptor */
  417. #ifndef Socket_defined
  418. typedef int    my_socket;    /* File descriptor for sockets */
  419. #define INVALID_SOCKET -1
  420. #endif
  421. /* Type for fuctions that handles signals */
  422. #define sig_handler RETSIGTYPE
  423. C_MODE_START
  424. typedef void    (*sig_return)();/* Returns type from signal */
  425. C_MODE_END
  426. #if defined(__GNUC__) && !defined(_lint)
  427. typedef char    pchar;        /* Mixed prototypes can take char */
  428. typedef char    puchar;        /* Mixed prototypes can take char */
  429. typedef char    pbool;        /* Mixed prototypes can take char */
  430. typedef short    pshort;        /* Mixed prototypes can take short int */
  431. typedef float    pfloat;        /* Mixed prototypes can take float */
  432. #else
  433. typedef int    pchar;        /* Mixed prototypes can't take char */
  434. typedef uint    puchar;        /* Mixed prototypes can't take char */
  435. typedef int    pbool;        /* Mixed prototypes can't take char */
  436. typedef int    pshort;        /* Mixed prototypes can't take short int */
  437. typedef double    pfloat;        /* Mixed prototypes can't take float */
  438. #endif
  439. C_MODE_START
  440. typedef int    (*qsort_cmp)(const void *,const void *);
  441. typedef int    (*qsort_cmp2)(void*, const void *,const void *);
  442. C_MODE_END
  443. #ifdef HAVE_mit_thread
  444. #define qsort_t void
  445. #undef QSORT_TYPE_IS_VOID
  446. #define QSORT_TYPE_IS_VOID
  447. #else
  448. #define qsort_t RETQSORTTYPE    /* Broken GCC cant handle typedef !!!! */
  449. #endif
  450. #ifdef HAVE_mit_thread
  451. #define size_socket socklen_t    /* Type of last arg to accept */
  452. #else
  453. #ifdef HAVE_SYS_SOCKET_H
  454. #include <sys/socket.h>
  455. #endif
  456. typedef SOCKET_SIZE_TYPE size_socket;
  457. #endif
  458.  
  459. #ifndef SOCKOPT_OPTLEN_TYPE
  460. #define SOCKOPT_OPTLEN_TYPE size_socket
  461. #endif
  462.  
  463. /* file create flags */
  464.  
  465. #ifndef O_SHARE            /* Probably not windows */
  466. #define O_SHARE        0    /* Flag to my_open for shared files */
  467. #ifndef O_BINARY
  468. #define O_BINARY    0    /* Flag to my_open for binary files */
  469. #endif
  470. #ifndef FILE_BINARY
  471. #define FILE_BINARY    O_BINARY /* Flag to my_fopen for binary streams */
  472. #endif
  473. #ifdef HAVE_FCNTL
  474. #define HAVE_FCNTL_LOCK
  475. #define F_TO_EOF    0L    /* Param to lockf() to lock rest of file */
  476. #endif
  477. #endif /* O_SHARE */
  478.  
  479. #ifndef O_TEMPORARY
  480. #define O_TEMPORARY    0
  481. #endif
  482. #ifndef O_SHORT_LIVED
  483. #define O_SHORT_LIVED    0
  484. #endif
  485.  
  486. /* #define USE_RECORD_LOCK    */
  487.  
  488.     /* Unsigned types supported by the compiler */
  489. #define UNSINT8            /* unsigned int8 (char) */
  490. #define UNSINT16        /* unsigned int16 */
  491. #define UNSINT32        /* unsigned int32 */
  492.  
  493.     /* General constants */
  494. #define SC_MAXWIDTH    256    /* Max width of screen (for error messages) */
  495. #define FN_LEN        256    /* Max file name len */
  496. #define FN_HEADLEN    253    /* Max length of filepart of file name */
  497. #define FN_EXTLEN    20    /* Max length of extension (part of FN_LEN) */
  498. #define FN_REFLEN    512    /* Max length of full path-name */
  499. #define FN_EXTCHAR    '.'
  500. #define FN_HOMELIB    '~'    /* ~/ is used as abbrev for home dir */
  501. #define FN_CURLIB    '.'    /* ./ is used as abbrev for current dir */
  502. #define FN_PARENTDIR    ".."    /* Parentdirectory; Must be a string */
  503. #define FN_DEVCHAR    ':'
  504.  
  505. #ifndef FN_LIBCHAR
  506. #ifdef __EMX__
  507. #define FN_LIBCHAR    '\\'
  508. #define FN_ROOTDIR    "\\"
  509. #else
  510. #define FN_LIBCHAR    '/'
  511. #define FN_ROOTDIR    "/"
  512. #endif
  513. #define MY_NFILE    1024    /* This is only used to save filenames */
  514. #endif
  515.  
  516. /* #define EXT_IN_LIBNAME     */
  517. /* #define FN_NO_CASE_SENCE   */
  518. /* #define FN_UPPER_CASE TRUE */
  519.  
  520. /*
  521.   Io buffer size; Must be a power of 2 and a multiple of 512. May be
  522.   smaller what the disk page size. This influences the speed of the
  523.   isam btree library. eg to big to slow.
  524. */
  525. #define IO_SIZE            4096
  526. /*
  527.   How much overhead does malloc have. The code often allocates
  528.   something like 1024-MALLOC_OVERHEAD bytes
  529. */
  530. #ifdef SAFEMALLOC
  531. #define MALLOC_OVERHEAD (8+24+4)
  532. #else
  533. #define MALLOC_OVERHEAD 8
  534. #endif
  535.     /* get memory in huncs */
  536. #define ONCE_ALLOC_INIT        (uint) (4096-MALLOC_OVERHEAD)
  537.     /* Typical record cash */
  538. #define RECORD_CACHE_SIZE    (uint) (64*1024-MALLOC_OVERHEAD)
  539.     /* Typical key cash */
  540. #define KEY_CACHE_SIZE        (uint) (8*1024*1024-MALLOC_OVERHEAD)
  541.  
  542.     /* Some things that this system doesn't have */
  543.  
  544. #define NO_HASH            /* Not needed anymore */
  545. #ifdef __WIN__
  546. #define NO_DIR_LIBRARY        /* Not standar dir-library */
  547. #define USE_MY_STAT_STRUCT    /* For my_lib */
  548. #endif
  549.  
  550. /* Some things that this system does have */
  551.  
  552. #ifndef HAVE_ITOA
  553. #define USE_MY_ITOA        /* There is no itoa */
  554. #endif
  555.  
  556. /* Some defines of functions for portability */
  557.  
  558. #ifndef HAVE_ATOD
  559. #define atod        atof
  560. #endif
  561. #ifdef USE_MY_ATOF
  562. #define atof        my_atof
  563. extern void        init_my_atof(void);
  564. extern double        my_atof(const char*);
  565. #endif
  566. #undef remove        /* Crashes MySQL on SCO 5.0.0 */
  567. #ifndef __WIN__
  568. #ifdef OS2
  569. #define closesocket(A)    soclose(A)
  570. #else
  571. #define closesocket(A)    close(A)
  572. #endif
  573. #ifndef ulonglong2double
  574. #define ulonglong2double(A) ((double) (A))
  575. #define my_off_t2double(A)  ((double) (A))
  576. #endif
  577. #endif
  578.  
  579. #ifndef offsetof
  580. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  581. #endif
  582. #define ulong_to_double(X) ((double) (ulong) (X))
  583. #define SET_STACK_SIZE(X)    /* Not needed on real machines */
  584.  
  585. #if !defined(HAVE_mit_thread) && !defined(HAVE_STRTOK_R)
  586. #define strtok_r(A,B,C) strtok((A),(B))
  587. #endif
  588.  
  589. /* Remove some things that mit_thread break or doesn't support */
  590. #if defined(HAVE_mit_thread) && defined(THREAD)
  591. #undef HAVE_PREAD
  592. #undef HAVE_REALPATH
  593. #undef HAVE_MLOCK
  594. #undef HAVE_TEMPNAM                /* Use ours */
  595. #undef HAVE_PTHREAD_SETPRIO
  596. #undef HAVE_FTRUNCATE
  597. #undef HAVE_READLINK
  598. #endif
  599.  
  600. /* This is from the old m-machine.h file */
  601.  
  602. #if SIZEOF_LONG_LONG > 4
  603. #define HAVE_LONG_LONG 1
  604. #endif
  605.  
  606. #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
  607. #define LONGLONG_MIN    ((long long) 0x8000000000000000LL)
  608. #define LONGLONG_MAX    ((long long) 0x7FFFFFFFFFFFFFFFLL)
  609. #endif
  610.  
  611. #if SIZEOF_LONG == 4
  612. #define INT_MIN32    (long) 0x80000000L
  613. #define INT_MAX32    (long) 0x7FFFFFFFL
  614. #define INT_MIN24    ((long) 0xff800000L)
  615. #define INT_MAX24    0x007fffffL
  616. #define INT_MIN16    ((short int) 0x8000)
  617. #define INT_MAX16    0x7FFF
  618. #define INT_MIN8    ((char) 0x80)
  619. #define INT_MAX8    ((char) 0x7F)
  620. #else  /* Probably Alpha */
  621. #define INT_MIN32    ((long) (int) 0x80000000)
  622. #define INT_MAX32    ((long) (int) 0x7FFFFFFF)
  623. #define INT_MIN24    ((long) (int) 0xff800000)
  624. #define INT_MAX24    ((long) (int) 0x007fffff)
  625. #define INT_MIN16    ((short int) 0xffff8000)
  626. #define INT_MAX16    ((short int) 0x00007FFF)
  627. #endif
  628.  
  629. /* From limits.h instead */
  630. #ifndef DBL_MIN
  631. #define DBL_MIN        4.94065645841246544e-324
  632. #define FLT_MIN        ((float)1.40129846432481707e-45)
  633. #endif
  634. #ifndef DBL_MAX
  635. #define DBL_MAX        1.79769313486231470e+308
  636. #define FLT_MAX        ((float)3.40282346638528860e+38)
  637. #endif
  638.  
  639. /*
  640.   Max size that must be added to a so that we know Size to make
  641.   adressable obj.
  642. */
  643. #if SIZEOF_CHARP == 4
  644. typedef long        my_ptrdiff_t;
  645. #else
  646. typedef long long    my_ptrdiff_t;
  647. #endif
  648.  
  649. #define MY_ALIGN(A,L)    (((A) + (L) - 1) & ~((L) - 1))
  650. #define ALIGN_SIZE(A)    MY_ALIGN((A),sizeof(double))
  651. /* Size to make adressable obj. */
  652. #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
  653.              /* Offset of filed f in structure t */
  654. #define OFFSET(t, f)    ((size_t)(char *)&((t *)0)->f)
  655. #define ADD_TO_PTR(ptr,size,type) (type) ((byte*) (ptr)+size)
  656. #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((byte*) (A) - (byte*) (B))
  657.  
  658. #define NullS        (char *) 0
  659. /* Nowdays we do not support MessyDos */
  660. #ifndef NEAR
  661. #define NEAR                /* Who needs segments ? */
  662. #define FAR                /* On a good machine */
  663. #ifndef HUGE_PTR
  664. #define HUGE_PTR
  665. #endif
  666. #endif
  667. #if defined(__IBMC__) || defined(__IBMCPP__)
  668. #define STDCALL _System _Export
  669. #elif !defined( STDCALL)
  670. #define STDCALL
  671. #endif
  672.  
  673. /* Typdefs for easyier portability */
  674.  
  675. #if defined(VOIDTYPE)
  676. typedef void    *gptr;        /* Generic pointer */
  677. #else
  678. typedef char    *gptr;        /* Generic pointer */
  679. #endif
  680. #ifndef HAVE_INT_8_16_32
  681. typedef char    int8;        /* Signed integer >= 8    bits */
  682. typedef short    int16;        /* Signed integer >= 16 bits */
  683. #endif
  684. #ifndef HAVE_UCHAR
  685. typedef unsigned char    uchar;    /* Short for unsigned char */
  686. #endif
  687. typedef unsigned char    uint8;    /* Short for unsigned integer >= 8  bits */
  688. typedef unsigned short    uint16; /* Short for unsigned integer >= 16 bits */
  689.  
  690. #if SIZEOF_INT == 4
  691. #ifndef HAVE_INT_8_16_32
  692. typedef int        int32;
  693. #endif
  694. typedef unsigned int    uint32; /* Short for unsigned integer >= 32 bits */
  695. #elif SIZEOF_LONG == 4
  696. #ifndef HAVE_INT_8_16_32
  697. typedef long        int32;
  698. #endif
  699. typedef unsigned long    uint32; /* Short for unsigned integer >= 32 bits */
  700. #else
  701. error "Neither int or long is of 4 bytes width"
  702. #endif
  703.  
  704. #if !defined(HAVE_ULONG) && !defined(HAVE_LINUXTHREADS) && !defined(__USE_MISC)
  705. typedef unsigned long    ulong;          /* Short for unsigned long */
  706. #endif
  707. #ifndef longlong_defined
  708. #if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8
  709. typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
  710. typedef long long int    longlong;
  711. #else
  712. typedef unsigned long    ulonglong;      /* ulong or unsigned long long */
  713. typedef long        longlong;
  714. #endif
  715. #endif
  716.  
  717. /* typedef used for length of string;  Should be unsigned! */
  718. typedef ulong        size_str;
  719.  
  720. #ifdef USE_RAID
  721. /*
  722.   The following is done with a if to not get problems with pre-processors
  723.   with late define evaluation
  724. */
  725. #if SIZEOF_OFF_T == 4
  726. #define SYSTEM_SIZEOF_OFF_T 4
  727. #else
  728. #define SYSTEM_SIZEOF_OFF_T 8
  729. #endif
  730. #undef  SIZEOF_OFF_T
  731. #define SIZEOF_OFF_T        8
  732. #else
  733. #define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
  734. #endif /* USE_RAID */
  735.  
  736. #if SIZEOF_OFF_T > 4
  737. typedef ulonglong my_off_t;
  738. #else
  739. typedef unsigned long my_off_t;
  740. #endif
  741. #define MY_FILEPOS_ERROR    (~(my_off_t) 0)
  742. #if !defined(__WIN__) && !defined(OS2)
  743. typedef off_t os_off_t;
  744. #endif
  745.  
  746. #if defined(__WIN__)
  747. #define socket_errno    WSAGetLastError()
  748. #define SOCKET_EINTR    WSAEINTR
  749. #define SOCKET_EAGAIN    WSAEINPROGRESS
  750. #define SOCKET_EWOULDBLOCK WSAEINPROGRESS
  751. #define SOCKET_ENFILE    ENFILE
  752. #define SOCKET_EMFILE    EMFILE
  753. #elif defined(OS2)
  754. #define socket_errno    sock_errno()
  755. #define SOCKET_EINTR    SOCEINTR
  756. #define SOCKET_EAGAIN    SOCEINPROGRESS
  757. #define SOCKET_EWOULDBLOCK SOCEWOULDBLOCK
  758. #define SOCKET_ENFILE    SOCENFILE
  759. #define SOCKET_EMFILE    SOCEMFILE
  760. #define closesocket(A)    soclose(A)
  761. #else /* Unix */
  762. #define socket_errno    errno
  763. #define closesocket(A)    close(A)
  764. #define SOCKET_EINTR    EINTR
  765. #define SOCKET_EAGAIN    EAGAIN
  766. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  767. #define SOCKET_ENFILE    ENFILE
  768. #define SOCKET_EMFILE    EMFILE
  769. #endif
  770.  
  771. typedef uint8        int7;    /* Most effective integer 0 <= x <= 127 */
  772. typedef short        int15;    /* Most effective integer 0 <= x <= 32767 */
  773. typedef char        *my_string; /* String of characters */
  774. typedef unsigned long    size_s; /* Size of strings (In string-funcs) */
  775. typedef int        myf;    /* Type of MyFlags in my_funcs */
  776. #ifndef byte_defined
  777. typedef char        byte;    /* Smallest addressable unit */
  778. #endif
  779. typedef char        my_bool; /* Small bool */
  780. #if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
  781. typedef char        bool;    /* Ordinary boolean values 0 1 */
  782. #endif
  783.     /* Macros for converting *constants* to the right type */
  784. #define INT8(v)        (int8) (v)
  785. #define INT16(v)    (int16) (v)
  786. #define INT32(v)    (int32) (v)
  787. #define MYF(v)        (myf) (v)
  788.  
  789. #ifndef LL
  790. #ifdef HAVE_LONG_LONG
  791. #define LL(A) A ## LL
  792. #else
  793. #define LL(A) A ## L
  794. #endif
  795. #endif
  796.  
  797. /*
  798.   Defines to make it possible to prioritize register assignments. No
  799.   longer that important with modern compilers.
  800. */
  801. #ifndef USING_X
  802. #define reg1 register
  803. #define reg2 register
  804. #define reg3 register
  805. #define reg4 register
  806. #define reg5 register
  807. #define reg6 register
  808. #define reg7 register
  809. #define reg8 register
  810. #define reg9 register
  811. #define reg10 register
  812. #define reg11 register
  813. #define reg12 register
  814. #define reg13 register
  815. #define reg14 register
  816. #define reg15 register
  817. #define reg16 register
  818. #endif
  819.  
  820. /*
  821.   Sometimes we want to make sure that the variable is not put into
  822.   a register in debugging mode so we can see its value in the core
  823. */
  824.  
  825. #ifndef DBUG_OFF
  826. #define dbug_volatile volatile
  827. #else
  828. #define dbug_volatile
  829. #endif
  830.  
  831. /* Defines for time function */
  832. #define SCALE_SEC    100
  833. #define SCALE_USEC    10000
  834. #define MY_HOW_OFTEN_TO_ALARM    2    /* How often we want info on screen */
  835. #define MY_HOW_OFTEN_TO_WRITE    1000    /* How often we want info on screen */
  836.  
  837. #ifndef set_timespec
  838. #ifdef HAVE_TIMESPEC_TS_SEC
  839. #define set_timespec(ABSTIME,SEC) { (ABSTIME).ts_sec=time(0) + (time_t) (SEC); (ABSTIME).ts_nsec=0; }
  840. #else
  841. #define set_timespec(ABSTIME,SEC) \
  842. {\
  843.   struct timeval tv;\
  844.   gettimeofday(&tv,0);\
  845.   (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
  846.   (ABSTIME).tv_nsec=tv.tv_usec*1000;\
  847. }
  848. #endif /* HAVE_TIMESPEC_TS_SEC */
  849. #endif /* set_timespec */
  850.  
  851. /*
  852.   Define-funktions for reading and storing in machine independent format
  853.   (low byte first)
  854. */
  855.  
  856. /* Optimized store functions for Intel x86 */
  857. #if defined(__i386__) && !defined(_WIN64)
  858. #define sint2korr(A)    (*((int16 *) (A)))
  859. #define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \
  860.                   (((uint32) 255L << 24) | \
  861.                    (((uint32) (uchar) (A)[2]) << 16) |\
  862.                    (((uint32) (uchar) (A)[1]) << 8) | \
  863.                    ((uint32) (uchar) (A)[0])) : \
  864.                   (((uint32) (uchar) (A)[2]) << 16) |\
  865.                   (((uint32) (uchar) (A)[1]) << 8) | \
  866.                   ((uint32) (uchar) (A)[0])))
  867. #define sint4korr(A)    (*((long *) (A)))
  868. #define uint2korr(A)    (*((uint16 *) (A)))
  869. #ifdef HAVE_purify
  870. #define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
  871.                   (((uint32) ((uchar) (A)[1])) << 8) +\
  872.                   (((uint32) ((uchar) (A)[2])) << 16))
  873. #else
  874. #define uint3korr(A)    (long) (*((unsigned long *) (A)) & 0xFFFFFF)
  875. #endif
  876. #define uint4korr(A)    (*((unsigned long *) (A)))
  877. #define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  878.                     (((uint32) ((uchar) (A)[1])) << 8) +\
  879.                     (((uint32) ((uchar) (A)[2])) << 16) +\
  880.                     (((uint32) ((uchar) (A)[3])) << 24)) +\
  881.                      (((ulonglong) ((uchar) (A)[4])) << 32))
  882. #define uint8korr(A)    (*((ulonglong *) (A)))
  883. #define sint8korr(A)    (*((longlong *) (A)))
  884. #define int2store(T,A)    *((uint16*) (T))= (uint16) (A)
  885. #define int3store(T,A)        { *(T)=  (uchar) ((A));\
  886.                   *(T+1)=(uchar) (((uint) (A) >> 8));\
  887.                   *(T+2)=(uchar) (((A) >> 16)); }
  888. #define int4store(T,A)    *((long *) (T))= (long) (A)
  889. #define int5store(T,A)    { *(T)= (uchar)((A));\
  890.               *((T)+1)=(uchar) (((A) >> 8));\
  891.               *((T)+2)=(uchar) (((A) >> 16));\
  892.               *((T)+3)=(uchar) (((A) >> 24)); \
  893.               *((T)+4)=(uchar) (((A) >> 32)); }
  894. #define int8store(T,A)    *((ulonglong *) (T))= (ulonglong) (A)
  895.  
  896. typedef union {
  897.   double v;
  898.   long m[2];
  899. } doubleget_union;
  900. #define doubleget(V,M)    \
  901. { doubleget_union _tmp; \
  902.   _tmp.m[0] = *((long*)(M)); \
  903.   _tmp.m[1] = *(((long*) (M))+1); \
  904.   (V) = _tmp.v; }
  905. #define doublestore(T,V) { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
  906.                *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; }
  907. #define float4get(V,M) { *((long *) &(V)) = *((long*) (M)); }
  908. #define float8get(V,M) doubleget((V),(M))
  909. #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float))
  910. #define float8store(V,M) doublestore((V),(M))
  911. #endif /* __i386__ */
  912.  
  913. #ifndef sint2korr
  914. #define sint2korr(A)    (int16) (((int16) ((uchar) (A)[0])) +\
  915.                  ((int16) ((int16) (A)[1]) << 8))
  916. #define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \
  917.                   (((uint32) 255L << 24) | \
  918.                    (((uint32) (uchar) (A)[2]) << 16) |\
  919.                    (((uint32) (uchar) (A)[1]) << 8) | \
  920.                    ((uint32) (uchar) (A)[0])) : \
  921.                   (((uint32) (uchar) (A)[2]) << 16) |\
  922.                   (((uint32) (uchar) (A)[1]) << 8) | \
  923.                   ((uint32) (uchar) (A)[0])))
  924. #define sint4korr(A)    (int32) (((int32) ((uchar) (A)[0])) +\
  925.                 (((int32) ((uchar) (A)[1]) << 8)) +\
  926.                 (((int32) ((uchar) (A)[2]) << 16)) +\
  927.                 (((int32) ((int16) (A)[3]) << 24)))
  928. #define sint8korr(A)    (longlong) uint8korr(A)
  929. #define uint2korr(A)    (uint16) (((uint16) ((uchar) (A)[0])) +\
  930.                   ((uint16) ((uchar) (A)[1]) << 8))
  931. #define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
  932.                   (((uint32) ((uchar) (A)[1])) << 8) +\
  933.                   (((uint32) ((uchar) (A)[2])) << 16))
  934. #define uint4korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
  935.                   (((uint32) ((uchar) (A)[1])) << 8) +\
  936.                   (((uint32) ((uchar) (A)[2])) << 16) +\
  937.                   (((uint32) ((uchar) (A)[3])) << 24))
  938. #define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  939.                     (((uint32) ((uchar) (A)[1])) << 8) +\
  940.                     (((uint32) ((uchar) (A)[2])) << 16) +\
  941.                     (((uint32) ((uchar) (A)[3])) << 24)) +\
  942.                      (((ulonglong) ((uchar) (A)[4])) << 32))
  943. #define uint8korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  944.                     (((uint32) ((uchar) (A)[1])) << 8) +\
  945.                     (((uint32) ((uchar) (A)[2])) << 16) +\
  946.                     (((uint32) ((uchar) (A)[3])) << 24)) +\
  947.             (((ulonglong) (((uint32) ((uchar) (A)[4])) +\
  948.                     (((uint32) ((uchar) (A)[5])) << 8) +\
  949.                     (((uint32) ((uchar) (A)[6])) << 16) +\
  950.                     (((uint32) ((uchar) (A)[7])) << 24))) <<\
  951.                      32))
  952. #define int2store(T,A)        { uint def_temp= (uint) (A) ;\
  953.                   *((uchar*) (T))=  (uchar)(def_temp); \
  954.                   *((uchar*) (T+1))=(uchar)((def_temp >> 8)); }
  955. #define int3store(T,A)        { /*lint -save -e734 */\
  956.                   *((uchar*)(T))=(uchar) ((A));\
  957.                   *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
  958.                   *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
  959.                   /*lint -restore */}
  960. #define int4store(T,A)        { *(T)=(char) ((A));\
  961.                   *((T)+1)=(char) (((A) >> 8));\
  962.                   *((T)+2)=(char) (((A) >> 16));\
  963.                   *((T)+3)=(char) (((A) >> 24)); }
  964. #define int5store(T,A)        { *(T)=((A));\
  965.                   *((T)+1)=(((A) >> 8));\
  966.                   *((T)+2)=(((A) >> 16));\
  967.                   *((T)+3)=(((A) >> 24)); \
  968.                   *((T)+4)=(((A) >> 32)); }
  969. #define int8store(T,A)        { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
  970.                   int4store((T),def_temp); \
  971.                   int4store((T+4),def_temp2); \
  972.                 }
  973. #ifdef WORDS_BIGENDIAN
  974. #define float4store(T,A)    { *(T)= ((byte *) &A)[3];\
  975.                               *((T)+1)=(char) ((byte *) &A)[2];\
  976.                               *((T)+2)=(char) ((byte *) &A)[1];\
  977.                               *((T)+3)=(char) ((byte *) &A)[0]; }
  978.  
  979. #define float4get(V,M)      { float def_temp;\
  980.                               ((byte*) &def_temp)[0]=(M)[3];\
  981.                               ((byte*) &def_temp)[1]=(M)[2];\
  982.                               ((byte*) &def_temp)[2]=(M)[1];\
  983.                               ((byte*) &def_temp)[3]=(M)[0];\
  984.                               (V)=def_temp; }
  985. #define float8store(T,V)    { *(T)= ((byte *) &V)[7];\
  986.                               *((T)+1)=(char) ((byte *) &V)[6];\
  987.                               *((T)+2)=(char) ((byte *) &V)[5];\
  988.                               *((T)+3)=(char) ((byte *) &V)[4];\
  989.                               *((T)+4)=(char) ((byte *) &V)[3];\
  990.                               *((T)+5)=(char) ((byte *) &V)[2];\
  991.                               *((T)+6)=(char) ((byte *) &V)[1];\
  992.                               *((T)+7)=(char) ((byte *) &V)[0]; }
  993.  
  994. #define float8get(V,M)        { double def_temp;\
  995.                               ((byte*) &def_temp)[0]=(M)[7];\
  996.                               ((byte*) &def_temp)[1]=(M)[6];\
  997.                               ((byte*) &def_temp)[2]=(M)[5];\
  998.                               ((byte*) &def_temp)[3]=(M)[4];\
  999.                               ((byte*) &def_temp)[4]=(M)[3];\
  1000.                               ((byte*) &def_temp)[5]=(M)[2];\
  1001.                               ((byte*) &def_temp)[6]=(M)[1];\
  1002.                               ((byte*) &def_temp)[7]=(M)[0];\
  1003.                   (V) = def_temp; }
  1004. #else
  1005. #define float4get(V,M)   memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float))
  1006. #define float4store(V,M) memcpy_fixed((byte*) V,(byte*) (&M),sizeof(float))
  1007.  
  1008. #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
  1009. #define doublestore(T,V)    { *(T)= ((byte *) &V)[4];\
  1010.                               *((T)+1)=(char) ((byte *) &V)[5];\
  1011.                               *((T)+2)=(char) ((byte *) &V)[6];\
  1012.                               *((T)+3)=(char) ((byte *) &V)[7];\
  1013.                               *((T)+4)=(char) ((byte *) &V)[0];\
  1014.                               *((T)+5)=(char) ((byte *) &V)[1];\
  1015.                               *((T)+6)=(char) ((byte *) &V)[2];\
  1016.                               *((T)+7)=(char) ((byte *) &V)[3]; }
  1017. #define doubleget(V,M) { double def_temp;\
  1018.                               ((byte*) &def_temp)[0]=(M)[4];\
  1019.                               ((byte*) &def_temp)[1]=(M)[5];\
  1020.                               ((byte*) &def_temp)[2]=(M)[6];\
  1021.                               ((byte*) &def_temp)[3]=(M)[7];\
  1022.                               ((byte*) &def_temp)[4]=(M)[0];\
  1023.                               ((byte*) &def_temp)[5]=(M)[1];\
  1024.                               ((byte*) &def_temp)[6]=(M)[2];\
  1025.                               ((byte*) &def_temp)[7]=(M)[3];\
  1026.                   (V) = def_temp; }
  1027. #endif /* __FLOAT_WORD_ORDER */
  1028.  
  1029. #define float8get(V,M)   doubleget((V),(M))
  1030. #define float8store(V,M) doublestore((V),(M))
  1031. #endif /* WORDS_BIGENDIAN */
  1032.  
  1033. #endif /* sint2korr */
  1034.  
  1035. /*
  1036.   Define-funktions for reading and storing in machine format from/to
  1037.   short/long to/from some place in memory V should be a (not
  1038.   register) variable, M is a pointer to byte
  1039. */
  1040.  
  1041. #ifdef WORDS_BIGENDIAN
  1042.  
  1043. #define ushortget(V,M)    { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
  1044.                     ((uint16) ((uint16) (M)[0]) << 8)); }
  1045. #define shortget(V,M)    { V = (short) (((short) ((uchar) (M)[1]))+\
  1046.                        ((short) ((short) (M)[0]) << 8)); }
  1047. #define longget(V,M)    { int32 def_temp;\
  1048.               ((byte*) &def_temp)[0]=(M)[0];\
  1049.               ((byte*) &def_temp)[1]=(M)[1];\
  1050.               ((byte*) &def_temp)[2]=(M)[2];\
  1051.               ((byte*) &def_temp)[3]=(M)[3];\
  1052.                 (V)=def_temp; }
  1053. #define ulongget(V,M)    { uint32 def_temp;\
  1054.               ((byte*) &def_temp)[0]=(M)[0];\
  1055.               ((byte*) &def_temp)[1]=(M)[1];\
  1056.               ((byte*) &def_temp)[2]=(M)[2];\
  1057.               ((byte*) &def_temp)[3]=(M)[3];\
  1058.                 (V)=def_temp; }
  1059. #define shortstore(T,A) { uint def_temp=(uint) (A) ;\
  1060.               *(T+1)=(char)(def_temp); \
  1061.               *(T+0)=(char)(def_temp >> 8); }
  1062. #define longstore(T,A)    { *((T)+3)=((A));\
  1063.               *((T)+2)=(((A) >> 8));\
  1064.               *((T)+1)=(((A) >> 16));\
  1065.               *((T)+0)=(((A) >> 24)); }
  1066.  
  1067. #define doubleget(V,M)     memcpy((byte*) &V,(byte*) (M),sizeof(double))
  1068. #define doublestore(T,V) memcpy((byte*) (T),(byte*) &V,sizeof(double))
  1069. #define longlongget(V,M) memcpy((byte*) &V,(byte*) (M),sizeof(ulonglong))
  1070. #define longlongstore(T,V) memcpy((byte*) (T),(byte*) &V,sizeof(ulonglong))
  1071.  
  1072. #else
  1073.  
  1074. #define ushortget(V,M)    { V = uint2korr(M); }
  1075. #define shortget(V,M)    { V = sint2korr(M); }
  1076. #define longget(V,M)    { V = sint4korr(M); }
  1077. #define ulongget(V,M)   { V = uint4korr(M); }
  1078. #define shortstore(T,V) int2store(T,V)
  1079. #define longstore(T,V)    int4store(T,V)
  1080. #ifndef doubleget
  1081. #define doubleget(V,M)     memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double))
  1082. #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double))
  1083. #endif /* doubleget */
  1084. #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong))
  1085. #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong))
  1086.  
  1087. #endif /* WORDS_BIGENDIAN */
  1088.  
  1089. /* sprintf does not always return the number of bytes :- */
  1090. #ifdef SPRINTF_RETURNS_INT
  1091. #define my_sprintf(buff,args) sprintf args
  1092. #else
  1093. #ifdef SPRINTF_RETURNS_PTR
  1094. #define my_sprintf(buff,args) ((int)(sprintf args - buff))
  1095. #else
  1096. #define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
  1097. #endif
  1098. #endif
  1099.  
  1100. #ifndef THREAD
  1101. #define thread_safe_increment(V,L) (V)++
  1102. #define thread_safe_add(V,C,L)     (V)+=(C)
  1103. #define thread_safe_sub(V,C,L)     (V)-=(C)
  1104. #define statistic_increment(V,L)   (V)++
  1105. #define statistic_add(V,C,L)       (V)+=(C)
  1106. #endif
  1107.  
  1108. #endif /* my_global_h */
  1109.