~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* This is the include file that should be included 'first' in every C file. */
17
18
#ifndef _global_h
19
#define _global_h
20
21
#define HAVE_REPLICATION
22
#define HAVE_EXTERNAL_CLIENT
23
24
/*
25
  InnoDB depends on some MySQL internals which other plugins should not
26
  need.  This is because of InnoDB's foreign key support, "safe" binlog
27
  truncation, and other similar legacy features.
28
29
  We define accessors for these internals unconditionally, but do not
30
  expose them in mysql/plugin.h.  They are declared in ha_innodb.h for
31
  InnoDB's use.
32
*/
33
#define INNODB_COMPATIBILITY_HOOKS
34
35
/* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
36
#ifdef USE_PRAGMA_IMPLEMENTATION
37
#define USE_PRAGMA_INTERFACE
38
#endif
39
40
#if defined(i386) && !defined(__i386__)
41
#define __i386__
42
#endif
43
44
/* Macros to make switching between C and C++ mode easier */
45
#ifdef __cplusplus
46
#define C_MODE_START    extern "C" {
47
#define C_MODE_END	}
48
#else
49
#define C_MODE_START
50
#define C_MODE_END
51
#endif
52
53
#include <my_config.h>
54
#if defined(__cplusplus) && defined(inline)
55
#undef inline				/* fix configure problem */
56
#endif
57
58
/* Make it easier to add conditionl code for windows */
59
#define IF_WIN(A,B) (B)
60
61
/* Some defines to avoid ifdefs in the code */
62
#ifndef NETWARE_YIELD
63
#define NETWARE_YIELD
64
#define NETWARE_SET_SCREEN_MODE(A)
65
#endif
66
67
68
/*
69
  The macros below are borrowed from include/linux/compiler.h in the
70
  Linux kernel. Use them to indicate the likelyhood of the truthfulness
71
  of a condition. This serves two purposes - newer versions of gcc will be
72
  able to optimize for branch predication, which could yield siginficant
73
  performance gains in frequently executed sections of the code, and the
74
  other reason to use them is for documentation
75
*/
76
77
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
78
#define __builtin_expect(x, expected_value) (x)
79
#endif
80
81
#define likely(x)	__builtin_expect((x),1)
82
#define unlikely(x)	__builtin_expect((x),0)
83
84
85
/*
86
  The macros below are useful in optimising places where it has been
87
  discovered that cache misses stall the process and where a prefetch
88
  of the cache line can improve matters. This is available in GCC 3.1.1
89
  and later versions.
90
  PREFETCH_READ says that addr is going to be used for reading and that
91
  it is to be kept in caches if possible for a while
92
  PREFETCH_WRITE also says that the item to be cached is likely to be
93
  updated.
94
  The *LOCALITY scripts are also available for experimentation purposes
95
  mostly and should only be used if they are verified to improve matters.
96
  For more input see GCC manual (available in GCC 3.1.1 and later)
97
*/
98
99
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
100
#define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
101
#define PREFETCH_WRITE(addr) \
102
  __builtin_prefetch(addr, 1, 3)
103
#define PREFETCH_READ_LOCALITY(addr, locality) \
104
  __builtin_prefetch(addr, 0, locality)
105
#define PREFETCH_WRITE_LOCALITY(addr, locality) \
106
  __builtin_prefetch(addr, 1, locality)
107
#else
108
#define PREFETCH_READ(addr)
109
#define PREFETCH_READ_LOCALITY(addr, locality)
110
#define PREFETCH_WRITE(addr)
111
#define PREFETCH_WRITE_LOCALITY(addr, locality)
112
#endif
113
114
/*
115
  The following macro is used to ensure that code often used in most
116
  SQL statements and definitely for parts of the SQL processing are
117
  kept in a code segment by itself. This has the advantage that the
118
  risk of common code being overlapping in caches of the CPU is less.
119
  This can be a cause of big performance problems.
120
  Routines should be put in this category with care and when they are
121
  put there one should also strive to make as much of the error handling
122
  as possible (or uncommon code of the routine) to execute in a
123
  separate method to avoid moving to much code to this code segment.
124
125
  It is very easy to use, simply add HOT_METHOD at the end of the
126
  function declaration.
127
  For more input see GCC manual (available in GCC 2.95 and later)
128
*/
129
130
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
131
#define HOT_METHOD \
132
  __attribute__ ((section ("hot_code_section")))
133
#else
134
#define HOT_METHOD
135
#endif
136
137
/*
138
  The following macro is used to ensure that popular global variables
139
  are located next to each other to avoid that they contend for the
140
  same cache lines.
141
142
  It is very easy to use, simply add HOT_DATA at the end of the declaration
143
  of the variable, the variable must be initialised because of the way
144
  that linker works so a declaration using HOT_DATA should look like:
145
  uint global_hot_data HOT_DATA = 0;
146
  For more input see GCC manual (available in GCC 2.95 and later)
147
*/
148
149
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
150
#define HOT_DATA \
151
  __attribute__ ((section ("hot_data_section")))
152
#else
153
#define HOT_DATA
154
#endif
155
156
/*
157
  now let's figure out if inline functions are supported
158
  autoconf defines 'inline' to be empty, if not
159
*/
160
#define inline_test_1(X)        X ## 1
161
#define inline_test_2(X)        inline_test_1(X)
162
#if inline_test_2(inline) != 1
163
#define HAVE_INLINE
164
#endif
165
#undef inline_test_2
166
#undef inline_test_1
167
/* helper macro for "instantiating" inline functions */
168
#define STATIC_INLINE static inline
169
170
/*
171
  The following macros are used to control inlining a bit more than
172
  usual. These macros are used to ensure that inlining always or
173
  never occurs (independent of compilation mode).
174
  For more input see GCC manual (available in GCC 3.1.1 and later)
175
*/
176
177
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
178
#define ALWAYS_INLINE __attribute__ ((always_inline))
179
#define NEVER_INLINE __attribute__ ((noinline))
180
#else
181
#define ALWAYS_INLINE
182
#define NEVER_INLINE
183
#endif
184
185
186
/* Fix problem with S_ISLNK() on Linux */
187
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
188
#undef  _GNU_SOURCE
189
#define _GNU_SOURCE 1
190
#endif
191
192
/*
193
  Temporary solution to solve bug#7156. Include "sys/types.h" before
194
  the thread headers, else the function madvise() will not be defined
195
*/
196
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
197
#include <sys/types.h>
198
#endif
199
200
/* The client defines this to avoid all thread code */
201
#if defined(UNDEF_THREADS_HACK)
202
#undef THREAD
203
#undef HAVE_LINUXTHREADS
204
#undef HAVE_NPTL
205
#endif
206
207
#ifdef HAVE_THREADS_WITHOUT_SOCKETS
208
/* MIT pthreads does not work with unix sockets */
209
#undef HAVE_SYS_UN_H
210
#endif
211
212
#define __EXTENSIONS__ 1	/* We want some extension */
213
#ifndef __STDC_EXT__
214
#define __STDC_EXT__ 1          /* To get large file support on hpux */
215
#endif
216
217
/*
218
  Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
219
220
    System Interfaces and Headers, Issue 5
221
222
  saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
223
  but apparently other systems (namely FreeBSD) don't agree.
224
225
  On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
226
  Furthermore, it tests that if a program requires older standard
227
  (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
228
  run on a new compiler (that defines _STDC_C99) and issues an #error.
229
  It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
230
  or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
231
232
  To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
233
  C++ compiler does not!
234
235
  So, in a desperate attempt to get correct prototypes for both
236
  C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
237
  depending on the compiler's announced C standard support.
238
239
  Cleaner solutions are welcome.
240
*/
241
#ifdef __sun
242
#if __STDC_VERSION__ - 0 >= 199901L
243
#define _XOPEN_SOURCE 600
244
#else
245
#define _XOPEN_SOURCE 500
246
#endif
247
#endif
248
249
#if defined(THREAD)
250
#ifndef _POSIX_PTHREAD_SEMANTICS
251
#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
252
#endif
253
254
#define _REENTRANT	1	/* Some thread libraries require this */
255
256
#if !defined(_THREAD_SAFE) && !defined(_AIX)
257
#define _THREAD_SAFE            /* Required for OSF1 */
258
#endif
259
260
#include <pthread.h>		/* AIX must have this included first */
261
262
#define _REENTRANT	1	/* Threads requires reentrant code */
263
#endif /* THREAD */
264
265
/* Go around some bugs in different OS and compilers */
266
267
#if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
268
#undef inline
269
#define inline
270
#endif
271
272
/* gcc/egcs issues */
273
274
#if defined(__GNUC) && defined(__EXCEPTIONS)
275
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
276
#endif
277
278
#ifndef stdin
279
#include <stdio.h>
280
#endif
281
#ifdef HAVE_STDLIB_H
282
#include <stdlib.h>
283
#endif
284
#ifdef HAVE_STDDEF_H
285
#include <stddef.h>
286
#endif
287
288
#include <math.h>
289
#ifdef HAVE_LIMITS_H
290
#include <limits.h>
291
#endif
292
#ifdef HAVE_FLOAT_H
293
#include <float.h>
294
#endif
295
296
#ifdef HAVE_SYS_TYPES_H
297
#include <sys/types.h>
298
#endif
299
#ifdef HAVE_FCNTL_H
300
#include <fcntl.h>
301
#endif
302
#ifdef HAVE_SYS_TIMEB_H
303
#include <sys/timeb.h>				/* Avoid warnings on SCO */
304
#endif
305
#if TIME_WITH_SYS_TIME
306
# include <sys/time.h>
307
# include <time.h>
308
#else
309
# if HAVE_SYS_TIME_H
310
#  include <sys/time.h>
311
# else
312
#  include <time.h>
313
# endif
314
#endif /* TIME_WITH_SYS_TIME */
315
#ifdef HAVE_UNISTD_H
316
#include <unistd.h>
317
#endif
318
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
319
#undef HAVE_ALLOCA
320
#undef HAVE_ALLOCA_H
321
#endif
322
#ifdef HAVE_ALLOCA_H
323
#include <alloca.h>
324
#endif
325
326
#include <errno.h>				/* Recommended by debian */
327
/* We need the following to go around a problem with openssl on solaris */
328
#if defined(HAVE_CRYPT_H)
329
#include <crypt.h>
330
#endif
331
332
/*
333
  A lot of our programs uses asserts, so better to always include it
334
  This also fixes a problem when people uses DBUG_ASSERT without including
335
  assert.h
336
*/
337
#include <assert.h>
338
339
/* an assert that works at compile-time. only for constant expression */
340
#ifndef __GNUC__
341
#define compile_time_assert(X)  do { } while(0)
342
#else
343
#define compile_time_assert(X)                                  \
344
  do                                                            \
345
  {                                                             \
346
    char compile_time_assert[(X) ? 1 : -1]                      \
347
                             __attribute__ ((unused));          \
348
  } while(0)
349
#endif
350
351
/* Declare madvise where it is not declared for C++, like Solaris */
352
#if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
353
extern "C" int madvise(void *addr, size_t len, int behav);
354
#endif
355
356
/* We can not live without the following defines */
357
358
#define USE_MYFUNC 1		/* Must use syscall indirection */
359
#define MASTER 1		/* Compile without unireg */
360
#define ENGLISH 1		/* Messages in English */
361
#define POSIX_MISTAKE 1		/* regexp: Fix stupid spec error */
362
#define USE_REGEX 1		/* We want the use the regex library */
363
/* Do not define for ultra sparcs */
364
#define USE_BMOVE512 1		/* Use this unless system bmove is faster */
365
366
#define QUOTE_ARG(x)		#x	/* Quote argument (before cpp) */
367
#define STRINGIFY_ARG(x) QUOTE_ARG(x)	/* Quote argument, after cpp */
368
/* Does the system remember a signal handler after a signal ? */
369
#ifndef HAVE_BSD_SIGNALS
370
#define DONT_REMEMBER_SIGNAL
371
#endif
372
373
/* Define void to stop lint from generating "null effekt" comments */
374
#ifndef DONT_DEFINE_VOID
375
#ifdef _lint
376
int	__void__;
377
#define VOID(X)		(__void__ = (int) (X))
378
#else
379
#undef VOID
380
#define VOID(X)		(X)
381
#endif
382
#endif /* DONT_DEFINE_VOID */
383
384
#if !defined(HAVE_UINT)
385
#undef HAVE_UINT
386
#define HAVE_UINT
387
typedef unsigned int uint;
388
typedef unsigned short ushort;
389
#endif
390
391
#define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
392
#define sgn(a)		(((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
393
#define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
394
#define test(a)		((a) ? 1 : 0)
395
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
396
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
397
#define test_all_bits(a,b) (((a) & (b)) == (b))
398
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
399
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
400
#ifndef HAVE_RINT
401
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
402
#endif
403
404
/* Define some general constants */
405
#ifndef TRUE
406
#define TRUE		(1)	/* Logical true */
407
#define FALSE		(0)	/* Logical false */
408
#endif
409
410
#if defined(__GNUC__)
411
#define function_volatile	volatile
412
#define my_reinterpret_cast(A) reinterpret_cast<A>
413
#define my_const_cast(A) const_cast<A>
414
# ifndef GCC_VERSION
415
#  define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
416
# endif
417
#elif !defined(my_reinterpret_cast)
418
#define my_reinterpret_cast(A) (A)
419
#define my_const_cast(A) (A)
420
#endif
421
422
#include <my_attribute.h>
423
424
/* From old s-system.h */
425
426
/*
427
  Support macros for non ansi & other old compilers. Since such
428
  things are no longer supported we do nothing. We keep then since
429
  some of our code may still be needed to upgrade old customers.
430
*/
431
#define _VARARGS(X) X
432
#define _STATIC_VARARGS(X) X
433
#define _PC(X)	X
434
435
/* The DBUG_ON flag always takes precedence over default DBUG_OFF */
436
#if defined(DBUG_ON) && defined(DBUG_OFF)
437
#undef DBUG_OFF
438
#endif
439
440
/* We might be forced to turn debug off, if not turned off already */
441
#if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
442
#  define DBUG_OFF
443
#  ifdef DBUG_ON
444
#    undef DBUG_ON
445
#  endif
446
#endif
447
448
#include <my_dbug.h>
449
450
#define MIN_ARRAY_SIZE	0	/* Zero or One. Gcc allows zero*/
451
#define ASCII_BITS_USED 8	/* Bit char used */
452
453
/* Some types that is different between systems */
454
455
typedef int	File;		/* File descriptor */
456
#ifndef Socket_defined
457
typedef int	my_socket;	/* File descriptor for sockets */
458
#define INVALID_SOCKET -1
459
#endif
460
/* Type for fuctions that handles signals */
461
#define sig_handler RETSIGTYPE
462
C_MODE_START
463
typedef void	(*sig_return)();/* Returns type from signal */
464
C_MODE_END
465
#if defined(__GNUC__) && !defined(_lint)
466
typedef char	pchar;		/* Mixed prototypes can take char */
467
typedef char	puchar;		/* Mixed prototypes can take char */
468
typedef char	pbool;		/* Mixed prototypes can take char */
469
typedef short	pshort;		/* Mixed prototypes can take short int */
470
typedef float	pfloat;		/* Mixed prototypes can take float */
471
#else
472
typedef int	pchar;		/* Mixed prototypes can't take char */
473
typedef uint	puchar;		/* Mixed prototypes can't take char */
474
typedef int	pbool;		/* Mixed prototypes can't take char */
475
typedef int	pshort;		/* Mixed prototypes can't take short int */
476
typedef double	pfloat;		/* Mixed prototypes can't take float */
477
#endif
478
C_MODE_START
479
typedef int	(*qsort_cmp)(const void *,const void *);
480
typedef int	(*qsort_cmp2)(void*, const void *,const void *);
481
C_MODE_END
482
#define qsort_t RETQSORTTYPE	/* Broken GCC cant handle typedef !!!! */
483
#ifdef HAVE_SYS_SOCKET_H
484
#include <sys/socket.h>
485
#endif
486
typedef SOCKET_SIZE_TYPE size_socket;
487
488
#ifndef SOCKOPT_OPTLEN_TYPE
489
#define SOCKOPT_OPTLEN_TYPE size_socket
490
#endif
491
492
/* file create flags */
493
494
#ifndef O_SHARE			/* Probably not windows */
495
#define O_SHARE		0	/* Flag to my_open for shared files */
496
#ifndef O_BINARY
497
#define O_BINARY	0	/* Flag to my_open for binary files */
498
#endif
499
#ifndef FILE_BINARY
500
#define FILE_BINARY	O_BINARY /* Flag to my_fopen for binary streams */
501
#endif
502
#ifdef HAVE_FCNTL
503
#define HAVE_FCNTL_LOCK
504
#define F_TO_EOF	0L	/* Param to lockf() to lock rest of file */
505
#endif
506
#endif /* O_SHARE */
507
508
#ifndef O_TEMPORARY
509
#define O_TEMPORARY	0
510
#endif
511
#ifndef O_SHORT_LIVED
512
#define O_SHORT_LIVED	0
513
#endif
514
#ifndef O_NOFOLLOW
515
#define O_NOFOLLOW      0
516
#endif
517
518
/* #define USE_RECORD_LOCK	*/
519
520
	/* Unsigned types supported by the compiler */
521
#define UNSINT8			/* unsigned int8 (char) */
522
#define UNSINT16		/* unsigned int16 */
523
#define UNSINT32		/* unsigned int32 */
524
525
	/* General constants */
526
#define SC_MAXWIDTH	256	/* Max width of screen (for error messages) */
527
#define FN_LEN		256	/* Max file name len */
528
#define FN_HEADLEN	253	/* Max length of filepart of file name */
529
#define FN_EXTLEN	20	/* Max length of extension (part of FN_LEN) */
530
#define FN_REFLEN	512	/* Max length of full path-name */
531
#define FN_EXTCHAR	'.'
532
#define FN_HOMELIB	'~'	/* ~/ is used as abbrev for home dir */
533
#define FN_CURLIB	'.'	/* ./ is used as abbrev for current dir */
534
#define FN_PARENTDIR	".."	/* Parent directory; Must be a string */
535
536
#ifndef FN_LIBCHAR
537
#define FN_LIBCHAR	'/'
538
#define FN_ROOTDIR	"/"
539
#endif
540
#define MY_NFILE	64	/* This is only used to save filenames */
541
#ifndef OS_FILE_LIMIT
542
#define OS_FILE_LIMIT	65535
543
#endif
544
545
/* #define EXT_IN_LIBNAME     */
546
/* #define FN_NO_CASE_SENCE   */
547
/* #define FN_UPPER_CASE TRUE */
548
549
/*
550
  Io buffer size; Must be a power of 2 and a multiple of 512. May be
551
  smaller what the disk page size. This influences the speed of the
552
  isam btree library. eg to big to slow.
553
*/
554
#define IO_SIZE			4096
555
/*
556
  How much overhead does malloc have. The code often allocates
557
  something like 1024-MALLOC_OVERHEAD bytes
558
*/
559
#define MALLOC_OVERHEAD 8
560
561
	/* get memory in huncs */
562
#define ONCE_ALLOC_INIT		(uint) (4096-MALLOC_OVERHEAD)
563
	/* Typical record cash */
564
#define RECORD_CACHE_SIZE	(uint) (64*1024-MALLOC_OVERHEAD)
565
	/* Typical key cash */
566
#define KEY_CACHE_SIZE		(uint) (8*1024*1024-MALLOC_OVERHEAD)
567
	/* Default size of a key cache block  */
568
#define KEY_CACHE_BLOCK_SIZE	(uint) 1024
569
570
571
	/* Some things that this system doesn't have */
572
573
#define NO_HASH			/* Not needed anymore */
574
575
/* Some defines of functions for portability */
576
577
#undef remove		/* Crashes MySQL on SCO 5.0.0 */
578
#define closesocket(A)	close(A)
579
#ifndef ulonglong2double
580
#define ulonglong2double(A) ((double) (ulonglong) (A))
581
#define my_off_t2double(A)  ((double) (my_off_t) (A))
582
#endif
583
584
#ifndef offsetof
585
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
586
#endif
587
#define ulong_to_double(X) ((double) (ulong) (X))
588
#define SET_STACK_SIZE(X)	/* Not needed on real machines */
589
590
#ifndef STACK_DIRECTION
591
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
592
#endif
593
594
#if !defined(HAVE_STRTOK_R)
595
#define strtok_r(A,B,C) strtok((A),(B))
596
#endif
597
598
/* This is from the old m-machine.h file */
599
600
#if SIZEOF_LONG_LONG > 4
601
#define HAVE_LONG_LONG 1
602
#endif
603
604
/*
605
  Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
606
  ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
607
  Also on Windows we define these constants by hand in config-win.h.
608
*/
609
610
#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
611
#define LONGLONG_MIN	((long long) 0x8000000000000000LL)
612
#define LONGLONG_MAX	((long long) 0x7FFFFFFFFFFFFFFFLL)
613
#endif
614
615
#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
616
/* First check for ANSI C99 definition: */
617
#ifdef ULLONG_MAX
618
#define ULONGLONG_MAX  ULLONG_MAX
619
#else
620
#define ULONGLONG_MAX ((unsigned long long)(~0ULL))
621
#endif
622
#endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
623
624
#define INT_MIN32       (~0x7FFFFFFFL)
625
#define INT_MAX32       0x7FFFFFFFL
626
#define UINT_MAX32      0xFFFFFFFFL
627
#define INT_MIN24       (~0x007FFFFF)
628
#define INT_MAX24       0x007FFFFF
629
#define UINT_MAX24      0x00FFFFFF
630
#define INT_MIN16       (~0x7FFF)
631
#define INT_MAX16       0x7FFF
632
#define UINT_MAX16      0xFFFF
633
#define INT_MIN8        (~0x7F)
634
#define INT_MAX8        0x7F
635
#define UINT_MAX8       0xFF
636
637
/* From limits.h instead */
638
#ifndef DBL_MIN
639
#define DBL_MIN		4.94065645841246544e-324
640
#define FLT_MIN		((float)1.40129846432481707e-45)
641
#endif
642
#ifndef DBL_MAX
643
#define DBL_MAX		1.79769313486231470e+308
644
#define FLT_MAX		((float)3.40282346638528860e+38)
645
#endif
646
#ifndef SIZE_T_MAX
647
#define SIZE_T_MAX ~((size_t) 0)
648
#endif
649
650
#ifndef isfinite
651
#ifdef HAVE_FINITE
652
#define isfinite(x) finite(x)
653
#else
654
#define finite(x) (1.0 / fabs(x) > 0.0)
655
#endif /* HAVE_FINITE */
656
#endif /* isfinite */
657
658
#ifndef HAVE_ISNAN
659
#define isnan(x) ((x) != (x))
660
#endif
661
662
#ifdef HAVE_ISINF
663
/* isinf() can be used in both C and C++ code */
664
#define my_isinf(X) isinf(X)
665
#else
666
#define my_isinf(X) (!isfinite(X) && !isnan(X))
667
#endif
668
669
/* Define missing math constants. */
670
#ifndef M_PI
671
#define M_PI 3.14159265358979323846
672
#endif
673
#ifndef M_E
674
#define M_E 2.7182818284590452354
675
#endif
676
#ifndef M_LN2
677
#define M_LN2 0.69314718055994530942
678
#endif
679
680
/*
681
  Max size that must be added to a so that we know Size to make
682
  adressable obj.
683
*/
684
#if SIZEOF_CHARP == 4
685
typedef long		my_ptrdiff_t;
686
#else
687
typedef long long	my_ptrdiff_t;
688
#endif
689
690
#define MY_ALIGN(A,L)	(((A) + (L) - 1) & ~((L) - 1))
691
#define ALIGN_SIZE(A)	MY_ALIGN((A),sizeof(double))
692
/* Size to make adressable obj. */
693
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
694
			 /* Offset of field f in structure t */
695
#define OFFSET(t, f)	((size_t)(char *)&((t *)0)->f)
696
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
697
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
698
699
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
700
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
701
702
/*
703
  Custom version of standard offsetof() macro which can be used to get
704
  offsets of members in class for non-POD types (according to the current
705
  version of C++ standard offsetof() macro can't be used in such cases and
706
  attempt to do so causes warnings to be emitted, OTOH in many cases it is
707
  still OK to assume that all instances of the class has the same offsets
708
  for the same members).
709
710
  This is temporary solution which should be removed once File_parser class
711
  and related routines are refactored.
712
*/
713
714
#define my_offsetof(TYPE, MEMBER) \
715
        ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
716
717
#define NullS		(char *) 0
718
719
#define STDCALL
720
721
/* Typdefs for easyier portability */
722
723
#ifndef HAVE_UCHAR
724
typedef unsigned char	uchar;	/* Short for unsigned char */
725
#endif
726
727
#ifndef HAVE_INT8
728
typedef signed char int8;       /* Signed integer >= 8  bits */
729
#endif
730
#ifndef HAVE_UINT8
731
typedef unsigned char uint8;    /* Unsigned integer >= 8  bits */
732
#endif
733
#ifndef HAVE_INT16
734
typedef short int16;
735
#endif
736
#ifndef HAVE_UINT16
737
typedef unsigned short uint16;
738
#endif
739
#if SIZEOF_INT == 4
740
#ifndef HAVE_INT32
741
typedef int int32;
742
#endif
743
#ifndef HAVE_UINT32
744
typedef unsigned int uint32;
745
#endif
746
#elif SIZEOF_LONG == 4
747
#ifndef HAVE_INT32
748
typedef long int32;
749
#endif
750
#ifndef HAVE_UINT32
751
typedef unsigned long uint32;
752
#endif
753
#else
754
#error Neither int or long is of 4 bytes width
755
#endif
756
757
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
758
typedef unsigned long	ulong;		  /* Short for unsigned long */
759
#endif
760
#ifndef longlong_defined
761
/* 
762
  Using [unsigned] long long is preferable as [u]longlong because we use 
763
  [unsigned] long long unconditionally in many places, 
764
  for example in constants with [U]LL suffix.
765
*/
766
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
767
typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
768
typedef long long int	longlong;
769
#else
770
typedef unsigned long	ulonglong;	  /* ulong or unsigned long long */
771
typedef long		longlong;
772
#endif
773
#endif
774
#ifndef HAVE_INT64
775
typedef longlong int64;
776
#endif
777
#ifndef HAVE_UINT64
778
typedef ulonglong uint64;
779
#endif
780
781
#if defined(NO_CLIENT_LONG_LONG)
782
typedef unsigned long my_ulonglong;
783
#else
784
typedef unsigned long long my_ulonglong;
785
#endif
786
787
#if SIZEOF_CHARP == SIZEOF_INT
788
typedef int intptr;
789
#elif SIZEOF_CHARP == SIZEOF_LONG
790
typedef long intptr;
791
#elif SIZEOF_CHARP == SIZEOF_LONG_LONG
792
typedef long long intptr;
793
#else
794
#error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
795
#endif
796
797
#define MY_ERRPTR ((void*)(intptr)1)
798
799
#ifdef USE_RAID
800
/*
801
  The following is done with a if to not get problems with pre-processors
802
  with late define evaluation
803
*/
804
#if SIZEOF_OFF_T == 4
805
#define SYSTEM_SIZEOF_OFF_T 4
806
#else
807
#define SYSTEM_SIZEOF_OFF_T 8
808
#endif
809
#undef  SIZEOF_OFF_T
810
#define SIZEOF_OFF_T	    8
811
#else
812
#define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
813
#endif /* USE_RAID */
814
815
#if SIZEOF_OFF_T > 4
816
typedef ulonglong my_off_t;
817
#else
818
typedef unsigned long my_off_t;
819
#endif
820
#define MY_FILEPOS_ERROR	(~(my_off_t) 0)
821
822
typedef off_t os_off_t;
823
824
#define socket_errno	errno
825
#define closesocket(A)	close(A)
826
#define SOCKET_EINTR	EINTR
827
#define SOCKET_EAGAIN	EAGAIN
828
#define SOCKET_ETIMEDOUT SOCKET_EINTR
829
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
830
#define SOCKET_EADDRINUSE EADDRINUSE
831
#define SOCKET_ENFILE	ENFILE
832
#define SOCKET_EMFILE	EMFILE
833
834
typedef uint8		int7;	/* Most effective integer 0 <= x <= 127 */
835
typedef short		int15;	/* Most effective integer 0 <= x <= 32767 */
836
typedef int		myf;	/* Type of MyFlags in my_funcs */
837
typedef char		my_bool; /* Small bool */
838
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
839
typedef char		bool;	/* Ordinary boolean values 0 1 */
840
#endif
841
	/* Macros for converting *constants* to the right type */
842
#define INT8(v)		(int8) (v)
843
#define INT16(v)	(int16) (v)
844
#define INT32(v)	(int32) (v)
845
#define MYF(v)		(myf) (v)
846
847
#ifndef LL
848
#ifdef HAVE_LONG_LONG
849
#define LL(A) A ## LL
850
#else
851
#define LL(A) A ## L
852
#endif
853
#endif
854
855
#ifndef ULL
856
#ifdef HAVE_LONG_LONG
857
#define ULL(A) A ## ULL
858
#else
859
#define ULL(A) A ## UL
860
#endif
861
#endif
862
863
/*
864
  Sometimes we want to make sure that the variable is not put into
865
  a register in debugging mode so we can see its value in the core
866
*/
867
868
#ifndef DBUG_OFF
869
#define dbug_volatile volatile
870
#else
871
#define dbug_volatile
872
#endif
873
874
/* Defines for time function */
875
#define SCALE_SEC	100
876
#define SCALE_USEC	10000
877
#define MY_HOW_OFTEN_TO_ALARM	2	/* How often we want info on screen */
878
#define MY_HOW_OFTEN_TO_WRITE	1000	/* How often we want info on screen */
879
880
881
882
/*
883
  Define-funktions for reading and storing in machine independent format
884
  (low byte first)
885
*/
886
887
/* Optimized store functions for Intel x86 */
888
#if defined(__i386__)
889
#define sint2korr(A)	(*((int16 *) (A)))
890
#define sint3korr(A)	((int32) ((((uchar) (A)[2]) & 128) ? \
891
				  (((uint32) 255L << 24) | \
892
				   (((uint32) (uchar) (A)[2]) << 16) |\
893
				   (((uint32) (uchar) (A)[1]) << 8) | \
894
				   ((uint32) (uchar) (A)[0])) : \
895
				  (((uint32) (uchar) (A)[2]) << 16) |\
896
				  (((uint32) (uchar) (A)[1]) << 8) | \
897
				  ((uint32) (uchar) (A)[0])))
898
#define sint4korr(A)	(*((long *) (A)))
899
#define uint2korr(A)	(*((uint16 *) (A)))
900
#if defined(HAVE_purify)
901
#define uint3korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
902
				  (((uint32) ((uchar) (A)[1])) << 8) +\
903
				  (((uint32) ((uchar) (A)[2])) << 16))
904
#else
905
/*
906
   ATTENTION !
907
   
908
    Please, note, uint3korr reads 4 bytes (not 3) !
909
    It means, that you have to provide enough allocated space !
910
*/
911
#define uint3korr(A)	(long) (*((unsigned int *) (A)) & 0xFFFFFF)
912
#endif /* HAVE_purify */
913
#define uint4korr(A)	(*((uint32 *) (A)))
914
#define uint5korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) +\
915
				    (((uint32) ((uchar) (A)[1])) << 8) +\
916
				    (((uint32) ((uchar) (A)[2])) << 16) +\
917
				    (((uint32) ((uchar) (A)[3])) << 24)) +\
918
				    (((ulonglong) ((uchar) (A)[4])) << 32))
919
#define uint6korr(A)	((ulonglong)(((uint32)    ((uchar) (A)[0]))          + \
920
                                     (((uint32)    ((uchar) (A)[1])) << 8)   + \
921
                                     (((uint32)    ((uchar) (A)[2])) << 16)  + \
922
                                     (((uint32)    ((uchar) (A)[3])) << 24)) + \
923
                         (((ulonglong) ((uchar) (A)[4])) << 32) +       \
924
                         (((ulonglong) ((uchar) (A)[5])) << 40))
925
#define uint8korr(A)	(*((ulonglong *) (A)))
926
#define sint8korr(A)	(*((longlong *) (A)))
927
#define int2store(T,A)	*((uint16*) (T))= (uint16) (A)
928
#define int3store(T,A)  do { *(T)=  (uchar) ((A));\
929
                            *(T+1)=(uchar) (((uint) (A) >> 8));\
930
                            *(T+2)=(uchar) (((A) >> 16)); } while (0)
931
#define int4store(T,A)	*((long *) (T))= (long) (A)
932
#define int5store(T,A)  do { *(T)= (uchar)((A));\
933
                             *((T)+1)=(uchar) (((A) >> 8));\
934
                             *((T)+2)=(uchar) (((A) >> 16));\
935
                             *((T)+3)=(uchar) (((A) >> 24)); \
936
                             *((T)+4)=(uchar) (((A) >> 32)); } while(0)
937
#define int6store(T,A)  do { *(T)=    (uchar)((A));          \
938
                             *((T)+1)=(uchar) (((A) >> 8));  \
939
                             *((T)+2)=(uchar) (((A) >> 16)); \
940
                             *((T)+3)=(uchar) (((A) >> 24)); \
941
                             *((T)+4)=(uchar) (((A) >> 32)); \
942
                             *((T)+5)=(uchar) (((A) >> 40)); } while(0)
943
#define int8store(T,A)	*((ulonglong *) (T))= (ulonglong) (A)
944
945
typedef union {
946
  double v;
947
  long m[2];
948
} doubleget_union;
949
#define doubleget(V,M)	\
950
do { doubleget_union _tmp; \
951
     _tmp.m[0] = *((long*)(M)); \
952
     _tmp.m[1] = *(((long*) (M))+1); \
953
     (V) = _tmp.v; } while(0)
954
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
955
			     *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
956
                         } while (0)
957
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
958
#define float8get(V,M)   doubleget((V),(M))
959
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
960
#define floatstore(T,V)  memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
961
#define floatget(V,M)    memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
962
#define float8store(V,M) doublestore((V),(M))
963
#else
964
965
/*
966
  We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
967
  were done before)
968
*/
969
#define sint2korr(A)	(int16) (((int16) ((uchar) (A)[0])) +\
970
				 ((int16) ((int16) (A)[1]) << 8))
971
#define sint3korr(A)	((int32) ((((uchar) (A)[2]) & 128) ? \
972
				  (((uint32) 255L << 24) | \
973
				   (((uint32) (uchar) (A)[2]) << 16) |\
974
				   (((uint32) (uchar) (A)[1]) << 8) | \
975
				   ((uint32) (uchar) (A)[0])) : \
976
				  (((uint32) (uchar) (A)[2]) << 16) |\
977
				  (((uint32) (uchar) (A)[1]) << 8) | \
978
				  ((uint32) (uchar) (A)[0])))
979
#define sint4korr(A)	(int32) (((int32) ((uchar) (A)[0])) +\
980
				(((int32) ((uchar) (A)[1]) << 8)) +\
981
				(((int32) ((uchar) (A)[2]) << 16)) +\
982
				(((int32) ((int16) (A)[3]) << 24)))
983
#define sint8korr(A)	(longlong) uint8korr(A)
984
#define uint2korr(A)	(uint16) (((uint16) ((uchar) (A)[0])) +\
985
				  ((uint16) ((uchar) (A)[1]) << 8))
986
#define uint3korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
987
				  (((uint32) ((uchar) (A)[1])) << 8) +\
988
				  (((uint32) ((uchar) (A)[2])) << 16))
989
#define uint4korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
990
				  (((uint32) ((uchar) (A)[1])) << 8) +\
991
				  (((uint32) ((uchar) (A)[2])) << 16) +\
992
				  (((uint32) ((uchar) (A)[3])) << 24))
993
#define uint5korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) +\
994
				    (((uint32) ((uchar) (A)[1])) << 8) +\
995
				    (((uint32) ((uchar) (A)[2])) << 16) +\
996
				    (((uint32) ((uchar) (A)[3])) << 24)) +\
997
				    (((ulonglong) ((uchar) (A)[4])) << 32))
998
#define uint6korr(A)	((ulonglong)(((uint32)    ((uchar) (A)[0]))          + \
999
                                     (((uint32)    ((uchar) (A)[1])) << 8)   + \
1000
                                     (((uint32)    ((uchar) (A)[2])) << 16)  + \
1001
                                     (((uint32)    ((uchar) (A)[3])) << 24)) + \
1002
                         (((ulonglong) ((uchar) (A)[4])) << 32) +       \
1003
                         (((ulonglong) ((uchar) (A)[5])) << 40))
1004
#define uint8korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) +\
1005
				    (((uint32) ((uchar) (A)[1])) << 8) +\
1006
				    (((uint32) ((uchar) (A)[2])) << 16) +\
1007
				    (((uint32) ((uchar) (A)[3])) << 24)) +\
1008
			(((ulonglong) (((uint32) ((uchar) (A)[4])) +\
1009
				    (((uint32) ((uchar) (A)[5])) << 8) +\
1010
				    (((uint32) ((uchar) (A)[6])) << 16) +\
1011
				    (((uint32) ((uchar) (A)[7])) << 24))) <<\
1012
				    32))
1013
#define int2store(T,A)       do { uint def_temp= (uint) (A) ;\
1014
                                  *((uchar*) (T))=  (uchar)(def_temp); \
1015
                                   *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
1016
                             } while(0)
1017
#define int3store(T,A)       do { /*lint -save -e734 */\
1018
                                  *((uchar*)(T))=(uchar) ((A));\
1019
                                  *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
1020
                                  *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
1021
                                  /*lint -restore */} while(0)
1022
#define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
1023
                                  *(((char *)(T))+1)=(char) (((A) >> 8));\
1024
                                  *(((char *)(T))+2)=(char) (((A) >> 16));\
1025
                                  *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
1026
#define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \
1027
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
1028
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
1029
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
1030
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
1031
		                } while(0)
1032
#define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \
1033
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
1034
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
1035
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
1036
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
1037
                                  *(((char *)(T))+5)= (char)(((A) >> 40)); \
1038
                                } while(0)
1039
#define int8store(T,A)       do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
1040
                                  int4store((T),def_temp); \
1041
                                  int4store((T+4),def_temp2); } while(0)
1042
#ifdef WORDS_BIGENDIAN
1043
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
1044
                              *((T)+1)=(char) ((uchar *) &A)[2];\
1045
                              *((T)+2)=(char) ((uchar *) &A)[1];\
1046
                              *((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
1047
1048
#define float4get(V,M)   do { float def_temp;\
1049
                              ((uchar*) &def_temp)[0]=(M)[3];\
1050
                              ((uchar*) &def_temp)[1]=(M)[2];\
1051
                              ((uchar*) &def_temp)[2]=(M)[1];\
1052
                              ((uchar*) &def_temp)[3]=(M)[0];\
1053
                              (V)=def_temp; } while(0)
1054
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
1055
                              *((T)+1)=(char) ((uchar *) &V)[6];\
1056
                              *((T)+2)=(char) ((uchar *) &V)[5];\
1057
                              *((T)+3)=(char) ((uchar *) &V)[4];\
1058
                              *((T)+4)=(char) ((uchar *) &V)[3];\
1059
                              *((T)+5)=(char) ((uchar *) &V)[2];\
1060
                              *((T)+6)=(char) ((uchar *) &V)[1];\
1061
                              *((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
1062
1063
#define float8get(V,M)   do { double def_temp;\
1064
                              ((uchar*) &def_temp)[0]=(M)[7];\
1065
                              ((uchar*) &def_temp)[1]=(M)[6];\
1066
                              ((uchar*) &def_temp)[2]=(M)[5];\
1067
                              ((uchar*) &def_temp)[3]=(M)[4];\
1068
                              ((uchar*) &def_temp)[4]=(M)[3];\
1069
                              ((uchar*) &def_temp)[5]=(M)[2];\
1070
                              ((uchar*) &def_temp)[6]=(M)[1];\
1071
                              ((uchar*) &def_temp)[7]=(M)[0];\
1072
                              (V) = def_temp; } while(0)
1073
#else
1074
#define float4get(V,M)   memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
1075
#define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
1076
1077
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
1078
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
1079
                              *(((char*)T)+1)=(char) ((uchar *) &V)[5];\
1080
                              *(((char*)T)+2)=(char) ((uchar *) &V)[6];\
1081
                              *(((char*)T)+3)=(char) ((uchar *) &V)[7];\
1082
                              *(((char*)T)+4)=(char) ((uchar *) &V)[0];\
1083
                              *(((char*)T)+5)=(char) ((uchar *) &V)[1];\
1084
                              *(((char*)T)+6)=(char) ((uchar *) &V)[2];\
1085
                              *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
1086
                         while(0)
1087
#define doubleget(V,M)   do { double def_temp;\
1088
                              ((uchar*) &def_temp)[0]=(M)[4];\
1089
                              ((uchar*) &def_temp)[1]=(M)[5];\
1090
                              ((uchar*) &def_temp)[2]=(M)[6];\
1091
                              ((uchar*) &def_temp)[3]=(M)[7];\
1092
                              ((uchar*) &def_temp)[4]=(M)[0];\
1093
                              ((uchar*) &def_temp)[5]=(M)[1];\
1094
                              ((uchar*) &def_temp)[6]=(M)[2];\
1095
                              ((uchar*) &def_temp)[7]=(M)[3];\
1096
                              (V) = def_temp; } while(0)
1097
#endif /* __FLOAT_WORD_ORDER */
1098
1099
#define float8get(V,M)   doubleget((V),(M))
1100
#define float8store(V,M) doublestore((V),(M))
1101
#endif /* WORDS_BIGENDIAN */
1102
1103
#endif /* __i386__ */
1104
1105
/*
1106
  Macro for reading 32-bit integer from network byte order (big-endian)
1107
  from unaligned memory location.
1108
*/
1109
#define int4net(A)        (int32) (((uint32) ((uchar) (A)[3]))        |\
1110
				  (((uint32) ((uchar) (A)[2])) << 8)  |\
1111
				  (((uint32) ((uchar) (A)[1])) << 16) |\
1112
				  (((uint32) ((uchar) (A)[0])) << 24))
1113
/*
1114
  Define-funktions for reading and storing in machine format from/to
1115
  short/long to/from some place in memory V should be a (not
1116
  register) variable, M is a pointer to byte
1117
*/
1118
1119
#ifdef WORDS_BIGENDIAN
1120
1121
#define ushortget(V,M)  do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
1122
                                 ((uint16) ((uint16) (M)[0]) << 8)); } while(0)
1123
#define shortget(V,M)   do { V = (short) (((short) ((uchar) (M)[1]))+\
1124
                                 ((short) ((short) (M)[0]) << 8)); } while(0)
1125
#define longget(V,M)    do { int32 def_temp;\
1126
                             ((uchar*) &def_temp)[0]=(M)[0];\
1127
                             ((uchar*) &def_temp)[1]=(M)[1];\
1128
                             ((uchar*) &def_temp)[2]=(M)[2];\
1129
                             ((uchar*) &def_temp)[3]=(M)[3];\
1130
                             (V)=def_temp; } while(0)
1131
#define ulongget(V,M)   do { uint32 def_temp;\
1132
                            ((uchar*) &def_temp)[0]=(M)[0];\
1133
                            ((uchar*) &def_temp)[1]=(M)[1];\
1134
                            ((uchar*) &def_temp)[2]=(M)[2];\
1135
                            ((uchar*) &def_temp)[3]=(M)[3];\
1136
                            (V)=def_temp; } while(0)
1137
#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
1138
                             *(((char*)T)+1)=(char)(def_temp); \
1139
                             *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
1140
#define longstore(T,A)  do { *(((char*)T)+3)=((A));\
1141
                             *(((char*)T)+2)=(((A) >> 8));\
1142
                             *(((char*)T)+1)=(((A) >> 16));\
1143
                             *(((char*)T)+0)=(((A) >> 24)); } while(0)
1144
1145
#define floatget(V,M)    memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
1146
#define floatstore(T,V)  memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
1147
#define doubleget(V,M)	 memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
1148
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
1149
#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
1150
#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
1151
1152
#else
1153
1154
#define ushortget(V,M)	do { V = uint2korr(M); } while(0)
1155
#define shortget(V,M)	do { V = sint2korr(M); } while(0)
1156
#define longget(V,M)	do { V = sint4korr(M); } while(0)
1157
#define ulongget(V,M)   do { V = uint4korr(M); } while(0)
1158
#define shortstore(T,V) int2store(T,V)
1159
#define longstore(T,V)	int4store(T,V)
1160
#ifndef floatstore
1161
#define floatstore(T,V)  memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
1162
#define floatget(V,M)    memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
1163
#endif
1164
#ifndef doubleget
1165
#define doubleget(V,M)	 memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
1166
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
1167
#endif /* doubleget */
1168
#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
1169
#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
1170
1171
#endif /* WORDS_BIGENDIAN */
1172
1173
/* sprintf does not always return the number of bytes :- */
1174
#ifdef SPRINTF_RETURNS_INT
1175
#define my_sprintf(buff,args) sprintf args
1176
#else
1177
#ifdef SPRINTF_RETURNS_PTR
1178
#define my_sprintf(buff,args) ((int)(sprintf args - buff))
1179
#else
1180
#define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
1181
#endif
1182
#endif
1183
1184
#ifndef THREAD
1185
#define thread_safe_increment(V,L) (V)++
1186
#define thread_safe_decrement(V,L) (V)--
1187
#define thread_safe_add(V,C,L)     (V)+=(C)
1188
#define thread_safe_sub(V,C,L)     (V)-=(C)
1189
#define statistic_increment(V,L)   (V)++
1190
#define statistic_decrement(V,L)   (V)--
1191
#define statistic_add(V,C,L)       (V)+=(C)
1192
#define statistic_sub(V,C,L)       (V)-=(C)
1193
#endif
1194
1195
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
1196
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
1197
#else
1198
#define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
1199
#endif
1200
1201
#ifdef HAVE_DLOPEN
1202
#if defined(HAVE_DLFCN_H)
1203
#include <dlfcn.h>
1204
#endif
1205
#endif
1206
1207
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
1208
#ifndef RTLD_NOW
1209
#define RTLD_NOW 1
1210
#endif
1211
1212
#ifndef HAVE_DLERROR
1213
#define dlerror() ""
1214
#endif
1215
1216
1217
/*
1218
 *  Include standard definitions of operator new and delete.
1219
 */
1220
#ifdef __cplusplus
1221
#include <new>
1222
#endif
1223
1224
/* Length of decimal number represented by INT32. */
1225
#define MY_INT32_NUM_DECIMAL_DIGITS 11
1226
1227
/* Length of decimal number represented by INT64. */
1228
#define MY_INT64_NUM_DECIMAL_DIGITS 21
1229
1230
/* Define some useful general macros (should be done after all headers). */
1231
#if !defined(max)
1232
#define max(a, b)	((a) > (b) ? (a) : (b))
1233
#define min(a, b)	((a) < (b) ? (a) : (b))
1234
#endif  
1235
/*
1236
  Only Linux is known to need an explicit sync of the directory to make sure a
1237
  file creation/deletion/renaming in(from,to) this directory durable.
1238
*/
1239
#ifdef TARGET_OS_LINUX
1240
#define NEED_EXPLICIT_SYNC_DIR 1
1241
#endif
1242
1243
#endif /* my_global_h */