~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_global.h

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

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