home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 July & August / PCWorld_2003-07-08_cd.bin / Software / Vyzkuste / mysql / data1.cab / Development / include / my_global.h < prev    next >
C/C++ Source or Header  |  2003-05-17  |  35KB  |  1,093 lines

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