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