Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1002 lines
31 KiB

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