home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / mysql / data1.cab / Development / include / my_global.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-01-22  |  31.2 KB  |  1,003 lines

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