~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

Merge of Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
 
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
 */
15
19
 
16
20
/* This is the include file that should be included 'first' in every C file. */
17
21
 
18
22
#ifndef DRIZZLE_SERVER_GLOBAL_H
19
23
#define DRIZZLE_SERVER_GLOBAL_H
20
24
 
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
25
#if defined(i386) && !defined(__i386__)
41
26
#define __i386__
42
27
#endif
43
28
 
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      }
 
29
#if defined(__sun) && defined(_FILE_OFFSET_BITS)
 
30
#undef _FILE_OFFSET_BITS
 
31
#endif
 
32
 
 
33
#include <config.h>
 
34
 
 
35
#if defined(__cplusplus)
 
36
 
 
37
# include CSTDINT_H
 
38
# include CINTTYPES_H
 
39
# include <cstdio>
 
40
# include <cstdlib>
 
41
# include <cstddef>
 
42
# include <cassert>
 
43
# include <cerrno>
 
44
# include <sstream>
 
45
# if defined(HAVE_MEMORY)
 
46
#  include <memory>
 
47
# endif
 
48
# if defined(HAVE_TR1_MEMORY)
 
49
#  include <tr1/memory>
 
50
# endif
 
51
# if defined(HAVE_BOOST_SHARED_PTR_HPP)
 
52
#  include <boost/shared_ptr.hpp>
 
53
# endif
48
54
#else
49
 
#define C_MODE_START
50
 
#define C_MODE_END
51
 
#endif
52
 
 
53
 
#include "config.h"
54
 
 
 
55
# include <stdint.h>
 
56
# include <inttypes.h>
 
57
# include <stdio.h>
 
58
# include <stdlib.h>
 
59
# include <stddef.h>
 
60
# include <errno.h>        /* Recommended by debian */
55
61
/*
56
 
  The macros below are borrowed from include/linux/compiler.h in the
57
 
  Linux kernel. Use them to indicate the likelyhood of the truthfulness
58
 
  of a condition. This serves two purposes - newer versions of gcc will be
59
 
  able to optimize for branch predication, which could yield siginficant
60
 
  performance gains in frequently executed sections of the code, and the
61
 
  other reason to use them is for documentation
 
62
  A lot of our programs uses asserts, so better to always include it
62
63
*/
63
 
 
64
 
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
65
 
#define __builtin_expect(x, expected_value) (x)
66
 
#endif
67
 
 
68
 
#define likely(x)       __builtin_expect((x),1)
69
 
#define unlikely(x)     __builtin_expect((x),0)
70
 
 
71
 
/*
72
 
 *   Disable __attribute__ for non GNU compilers, since we're using them
73
 
 *     only to either generate or suppress warnings.
74
 
 *     */
75
 
#ifndef __attribute__
76
 
# if !defined(__GNUC__)
77
 
#  define __attribute__(A)
78
 
# endif
79
 
#endif
80
 
 
81
 
 
82
 
/* Fix problem with S_ISLNK() on Linux */
83
 
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
84
 
#undef  _GNU_SOURCE
85
 
#define _GNU_SOURCE 1
86
 
#endif
87
 
 
 
64
# include <assert.h>
 
65
 
 
66
#endif // __cplusplus
 
67
 
 
68
#include <math.h>
 
69
 
 
70
#ifndef EOVERFLOW
 
71
#define EOVERFLOW 84
 
72
#endif
 
73
 
 
74
 
 
75
#if TIME_WITH_SYS_TIME
 
76
# include <sys/time.h>
 
77
# include <time.h>
 
78
#else
 
79
# if HAVE_SYS_TIME_H
 
80
#  include <sys/time.h>
 
81
# else
 
82
#  include <time.h>
 
83
# endif
 
84
#endif
 
85
 
 
86
 
 
87
#if defined(__cplusplus)
 
88
# if !defined(SHARED_PTR_NAMESPACE)
 
89
#  error SHARED_PTR_NAMESPACE not defined, configure error!
 
90
# endif
 
91
# if defined(SHARED_PTR_NAMESPACE)
 
92
//We aren't using this yet - don't actually put in code yet.
 
93
//using SHARED_PTR_NAMESPACE::shared_ptr;
 
94
# endif
 
95
#endif /* defined(SHARED_PTR_NAMESPACE) */
88
96
 
89
97
/*
90
98
  Temporary solution to solve bug#7156. Include "sys/types.h" before
94
102
#include <sys/types.h>
95
103
#endif
96
104
 
97
 
#define __EXTENSIONS__ 1        /* We want some extension */
98
 
 
99
 
#if defined(HAVE_STDINT_H)
100
 
/* Need to include this _before_ stdlib, so that all defines are right */
101
 
/* We are mixing C and C++, so we wan the C limit macros in the C++ too */
102
 
/* Enable some extra C99 extensions */
103
 
#undef _STDINT_H
104
 
#define __STDC_FORMAT_MACROS
105
 
#include <inttypes.h>
106
 
/* 
107
 
  We include the following because currently Google #$@#$ Protocol Buffers possibly break stdint defines. 
108
 
  Or I am wrong, very possible, and hope someone finds the solution.
109
 
 
110
 
  Taken from /usr/include/stdint.h
111
 
*/
112
 
 
113
 
/* 7.18.2 Limits of specified-width integer types:
114
 
 *   These #defines specify the minimum and maximum limits
115
 
 *   of each of the types declared above.
116
 
 */
117
 
 
118
 
 
119
 
#if (!defined(INT16_MAX))
120
 
/* 7.18.2.1 Limits of exact-width integer types */
121
 
#define INT8_MAX         127
122
 
#define INT16_MAX        32767
123
 
#define INT32_MAX        2147483647
124
 
#define INT64_MAX        9223372036854775807LL
125
 
 
126
 
#define INT8_MIN          -128
127
 
#define INT16_MIN         -32768
128
 
 
129
 
   /*
130
 
      Note:  the literal "most negative int" cannot be written in C --
131
 
      the rules in the standard (section 6.4.4.1 in C99) will give it
132
 
      an unsigned type, so INT32_MIN (and the most negative member of
133
 
      any larger signed type) must be written via a constant expression.
134
 
   */
135
 
#define INT32_MIN        (-INT32_MAX-1)
136
 
#define INT64_MIN        (-INT64_MAX-1)
137
 
 
138
 
#define UINT8_MAX         255
139
 
#define UINT16_MAX        65535
140
 
#define UINT32_MAX        4294967295U
141
 
#define UINT64_MAX        18446744073709551615ULL
142
 
 
143
 
/* 7.18.2.2 Limits of minimum-width integer types */
144
 
#define INT_LEAST8_MIN    INT8_MIN
145
 
#define INT_LEAST16_MIN   INT16_MIN
146
 
#define INT_LEAST32_MIN   INT32_MIN
147
 
#define INT_LEAST64_MIN   INT64_MIN
148
 
 
149
 
#define INT_LEAST8_MAX    INT8_MAX
150
 
#define INT_LEAST16_MAX   INT16_MAX
151
 
#define INT_LEAST32_MAX   INT32_MAX
152
 
#define INT_LEAST64_MAX   INT64_MAX
153
 
 
154
 
#define UINT_LEAST8_MAX   UINT8_MAX
155
 
#define UINT_LEAST16_MAX  UINT16_MAX
156
 
#define UINT_LEAST32_MAX  UINT32_MAX
157
 
#define UINT_LEAST64_MAX  UINT64_MAX
158
 
 
159
 
/* 7.18.2.3 Limits of fastest minimum-width integer types */
160
 
#define INT_FAST8_MIN     INT8_MIN
161
 
#define INT_FAST16_MIN    INT16_MIN
162
 
#define INT_FAST32_MIN    INT32_MIN
163
 
#define INT_FAST64_MIN    INT64_MIN
164
 
 
165
 
#define INT_FAST8_MAX     INT8_MAX
166
 
#define INT_FAST16_MAX    INT16_MAX
167
 
#define INT_FAST32_MAX    INT32_MAX
168
 
#define INT_FAST64_MAX    INT64_MAX
169
 
 
170
 
#define UINT_FAST8_MAX    UINT8_MAX
171
 
#define UINT_FAST16_MAX   UINT16_MAX
172
 
#define UINT_FAST32_MAX   UINT32_MAX
173
 
#define UINT_FAST64_MAX   UINT64_MAX
174
 
 
175
 
/* 7.18.2.4 Limits of integer types capable of holding object pointers */
176
 
 
177
 
#if __WORDSIZE == 64
178
 
#define INTPTR_MIN        INT64_MIN
179
 
#define INTPTR_MAX        INT64_MAX
180
 
#else
181
 
#define INTPTR_MIN        INT32_MIN
182
 
#define INTPTR_MAX        INT32_MAX
183
 
#endif
184
 
 
185
 
#if __WORDSIZE == 64
186
 
#define UINTPTR_MAX       UINT64_MAX
187
 
#else
188
 
#define UINTPTR_MAX       UINT32_MAX
189
 
#endif
190
 
 
191
 
/* 7.18.2.5 Limits of greatest-width integer types */
192
 
#define INTMAX_MIN        INT64_MIN
193
 
#define INTMAX_MAX        INT64_MAX
194
 
 
195
 
#define UINTMAX_MAX       UINT64_MAX
196
 
 
197
 
/* 7.18.3 "Other" */
198
 
#if __WORDSIZE == 64
199
 
#define PTRDIFF_MIN       INT64_MIN
200
 
#define PTRDIFF_MAX       INT64_MAX
201
 
#else
202
 
#define PTRDIFF_MIN       INT32_MIN
203
 
#define PTRDIFF_MAX       INT32_MAX
204
 
#endif
205
 
 
206
 
/* We have no sig_atomic_t yet, so no SIG_ATOMIC_{MIN,MAX}.
207
 
   Should end up being {-127,127} or {0,255} ... or bigger.
208
 
   My bet would be on one of {U}INT32_{MIN,MAX}. */
209
 
 
210
 
#if __WORDSIZE == 64
211
 
#define SIZE_MAX          UINT64_MAX
212
 
#else
213
 
#define SIZE_MAX          UINT32_MAX
214
 
#endif
215
 
 
216
 
#ifndef WCHAR_MAX
217
 
#  ifdef __WCHAR_MAX__
218
 
#    define WCHAR_MAX     __WCHAR_MAX__
219
 
#  else
220
 
#    define WCHAR_MAX     0x7fffffff
221
 
#  endif
222
 
#endif
223
 
 
224
 
/* WCHAR_MIN should be 0 if wchar_t is an unsigned type and
225
 
   (-WCHAR_MAX-1) if wchar_t is a signed type.  Unfortunately,
226
 
   it turns out that -fshort-wchar changes the signedness of
227
 
   the type. */
228
 
#ifndef WCHAR_MIN
229
 
#  if WCHAR_MAX == 0xffff
230
 
#    define WCHAR_MIN       0
231
 
#  else
232
 
#    define WCHAR_MIN       (-WCHAR_MAX-1)
233
 
#  endif
234
 
#endif
235
 
 
236
 
#define WINT_MIN          INT32_MIN
237
 
#define WINT_MAX          INT32_MAX
238
 
 
239
 
#define SIG_ATOMIC_MIN    INT32_MIN
240
 
#define SIG_ATOMIC_MAX    INT32_MAX
241
 
#endif
242
 
 
243
 
#else
244
 
#error "You must have inttypes!"
245
 
#endif
246
 
 
247
 
 
248
 
/*
249
 
  Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
250
 
 
251
 
    System Interfaces and Headers, Issue 5
252
 
 
253
 
  saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
254
 
  but apparently other systems (namely FreeBSD) don't agree.
255
 
 
256
 
  On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
257
 
  Furthermore, it tests that if a program requires older standard
258
 
  (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
259
 
  run on a new compiler (that defines _STDC_C99) and issues an #error.
260
 
  It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
261
 
  or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
262
 
 
263
 
  To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
264
 
  C++ compiler does not!
265
 
 
266
 
  So, in a desperate attempt to get correct prototypes for both
267
 
  C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
268
 
  depending on the compiler's announced C standard support.
269
 
 
270
 
  Cleaner solutions are welcome.
271
 
*/
272
 
#ifdef __sun
273
 
#if __STDC_VERSION__ - 0 >= 199901L
274
 
#define _XOPEN_SOURCE 600
275
 
#else
276
 
#define _XOPEN_SOURCE 500
277
 
#endif
278
 
#endif
279
 
 
280
 
#ifndef _POSIX_PTHREAD_SEMANTICS
281
 
#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
282
 
#endif
283
 
 
284
 
#define _REENTRANT      1       /* Some thread libraries require this */
285
 
 
286
 
#include <pthread.h>            /* AIX must have this included first */
287
 
 
288
 
#define _REENTRANT      1       /* Threads requires reentrant code */
289
 
 
290
 
 
291
 
/* gcc/egcs issues */
292
 
 
293
 
#if defined(__GNUC) && defined(__EXCEPTIONS)
294
 
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
295
 
#endif
296
 
 
297
 
#ifndef stdin
298
 
#include <stdio.h>
299
 
#endif
300
 
#ifdef HAVE_STDLIB_H
301
 
#include <stdlib.h>
302
 
#endif
303
 
#ifdef HAVE_STDDEF_H
304
 
#include <stddef.h>
305
 
#endif
306
 
 
307
 
#include <math.h>
 
105
 
 
106
#include <pthread.h>    /* AIX must have this included first */
 
107
 
 
108
#define _REENTRANT  1  /* Threads requires reentrant code */
 
109
 
308
110
#ifdef HAVE_LIMITS_H
309
111
#include <limits.h>
310
112
#endif
315
117
#ifdef HAVE_FCNTL_H
316
118
#include <fcntl.h>
317
119
#endif
318
 
#ifdef HAVE_SYS_TIMEB_H
319
 
#include <sys/timeb.h>                          /* Avoid warnings on SCO */
320
 
#endif
321
 
#if TIME_WITH_SYS_TIME
322
 
# include <sys/time.h>
323
 
# include <time.h>
324
 
#else
325
 
# if HAVE_SYS_TIME_H
326
 
#  include <sys/time.h>
327
 
# else
328
 
#  include <time.h>
329
 
# endif
330
 
#endif /* TIME_WITH_SYS_TIME */
 
120
 
331
121
#ifdef HAVE_UNISTD_H
332
122
#include <unistd.h>
333
123
#endif
334
 
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
335
 
#undef HAVE_ALLOCA
336
 
#undef HAVE_ALLOCA_H
337
 
#endif
338
 
#ifdef HAVE_ALLOCA_H
339
 
#include <alloca.h>
340
 
#endif
341
 
 
342
 
#include <errno.h>                              /* Recommended by debian */
343
 
 
344
 
#if defined(HAVE_STDBOOL_H)
345
 
#include <stdbool.h>
346
 
#endif
 
124
 
347
125
 
348
126
#ifdef HAVE_SYS_STAT_H
349
127
# include <sys/stat.h>
350
128
#endif
351
129
 
352
 
/*
353
 
  A lot of our programs uses asserts, so better to always include it
354
 
*/
355
 
#include <assert.h>
356
 
 
357
 
/* an assert that works at compile-time. only for constant expression */
358
 
#ifndef __GNUC__
359
 
#define compile_time_assert(X)  do { } while(0)
360
 
#else
361
 
#define compile_time_assert(X)                                  \
362
 
  do                                                            \
363
 
  {                                                             \
364
 
    char compile_time_assert[(X) ? 1 : -1]                      \
365
 
                             __attribute__ ((unused));          \
366
 
  } while(0)
367
 
#endif
368
 
 
369
 
/* Declare madvise where it is not declared for C++, like Solaris */
370
 
#if HAVE_MADVISE && !defined(HAVE_DECL_MADVISE) && defined(__cplusplus)
371
 
extern "C" int madvise(void *addr, size_t len, int behav);
372
 
#endif
373
 
 
374
 
/* We can not live without the following defines */
375
 
 
376
 
#define USE_MYFUNC 1            /* Must use syscall indirection */
377
 
#define MASTER 1                /* Compile without unireg */
378
 
#define ENGLISH 1               /* Messages in English */
379
 
#define POSIX_MISTAKE 1         /* regexp: Fix stupid spec error */
380
 
 
381
 
#define QUOTE_ARG(x)            #x      /* Quote argument (before cpp) */
382
 
#define STRINGIFY_ARG(x) QUOTE_ARG(x)   /* Quote argument, after cpp */
383
 
/* Does the system remember a signal handler after a signal ? */
384
 
#ifndef HAVE_BSD_SIGNALS
385
 
#define DONT_REMEMBER_SIGNAL
386
 
#endif
387
 
 
388
 
/* Define void to stop lint from generating "null effekt" comments */
389
 
#ifndef DONT_DEFINE_VOID
390
 
#ifdef _lint
391
 
int     __void__;
392
 
#define VOID(X)         (__void__ = (int) (X))
393
 
#else
394
 
#undef VOID
395
 
#define VOID(X)         (X)
396
 
#endif
397
 
#endif /* DONT_DEFINE_VOID */
398
 
 
399
 
#if !defined(HAVE_UINT)
400
 
#undef HAVE_UINT
401
 
#define HAVE_UINT
402
 
typedef unsigned int uint;
403
 
typedef unsigned short ushort;
404
 
#endif
405
 
 
406
130
/* Declared in int2str() */
407
131
extern char _dig_vec_upper[];
408
132
extern char _dig_vec_lower[];
409
133
 
410
 
#define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
411
 
#define sgn(a)          (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
412
 
#define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
413
 
#define test(a)         ((a) ? 1 : 0)
 
134
#ifdef __cplusplus
 
135
template <class T> void set_if_bigger(T &a, const T &b)
 
136
{
 
137
  if (a < b)
 
138
    a=b;
 
139
}
 
140
 
 
141
template <class T> void set_if_smaller(T &a, const T &b)
 
142
{
 
143
  if (a > b)
 
144
    a=b;
 
145
}
 
146
#else
 
147
#ifdef __GNUC__
 
148
#define set_if_bigger(a,b) do {                 \
 
149
  const typeof(a) _a = (a);                     \
 
150
  const typeof(b) _b = (b);                     \
 
151
  (void) (&_a == &_b);                          \
 
152
  if ((a) < (b)) (a)=(b);                       \
 
153
  } while(0)
 
154
#define set_if_smaller(a,b) do {                \
 
155
  const typeof(a) _a = (a);                     \
 
156
  const typeof(b) _b = (b);                     \
 
157
  (void) (&_a == &_b);                          \
 
158
  if ((a) > (b)) (a)=(b);                       \
 
159
  } while(0)
 
160
 
 
161
#else
414
162
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
415
163
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
416
 
#define test_all_bits(a,b) (((a) & (b)) == (b))
417
 
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
418
 
#define array_elements(A) ((uint32_t) (sizeof(A)/sizeof(A[0])))
419
 
#ifndef HAVE_RINT
420
 
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
421
 
#endif
422
 
 
423
 
#if defined(__GNUC__)
424
 
#define function_volatile       volatile
425
 
#define my_reinterpret_cast(A) reinterpret_cast<A>
426
 
#define my_const_cast(A) const_cast<A>
427
 
# ifndef GCC_VERSION
428
 
#  define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
429
 
# endif
430
 
#elif !defined(my_reinterpret_cast)
431
 
#define my_reinterpret_cast(A) (A)
432
 
#define my_const_cast(A) (A)
433
 
#endif
434
 
 
435
 
/* From old s-system.h */
436
 
 
437
 
/*
438
 
  Support macros for non ansi & other old compilers. Since such
439
 
  things are no longer supported we do nothing. We keep then since
440
 
  some of our code may still be needed to upgrade old customers.
441
 
*/
442
 
#define _VARARGS(X) X
443
 
#define _STATIC_VARARGS(X) X
444
 
#define _PC(X)  X
445
 
 
446
 
#define MIN_ARRAY_SIZE  0       /* Zero or One. Gcc allows zero*/
447
 
#define ASCII_BITS_USED 8       /* Bit char used */
 
164
#endif
 
165
#endif
 
166
 
 
167
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
448
168
 
449
169
/* Some types that is different between systems */
450
170
 
451
 
typedef int     File;           /* File descriptor */
452
 
/* Type for fuctions that handles signals */
453
 
#define sig_handler RETSIGTYPE
454
 
C_MODE_START
455
 
typedef void    (*sig_return)(void);/* Returns type from signal */
456
 
typedef int     (*qsort_cmp)(const void *,const void *);
457
 
typedef int     (*qsort_cmp2)(void*, const void *,const void *);
458
 
C_MODE_END
459
 
#define qsort_t RETQSORTTYPE    /* Broken GCC cant handle typedef !!!! */
 
171
typedef int  File;    /* File descriptor */
 
172
 
460
173
#ifdef HAVE_SYS_SOCKET_H
461
174
#include <sys/socket.h>
462
175
#endif
463
 
typedef SOCKET_SIZE_TYPE size_socket;
464
 
 
465
 
#ifndef SOCKOPT_OPTLEN_TYPE
466
 
#define SOCKOPT_OPTLEN_TYPE size_socket
467
 
#endif
468
 
 
469
 
/* file create flags */
470
 
 
471
 
#ifndef O_SHARE                 /* Probably not windows */
472
 
#define O_SHARE         0       /* Flag to my_open for shared files */
473
 
#endif /* O_SHARE */
474
 
 
475
 
#ifndef O_BINARY
476
 
#define O_BINARY        0       /* Flag to my_open for binary files */
477
 
#endif
478
 
 
479
 
#ifndef FILE_BINARY
480
 
#define FILE_BINARY     O_BINARY /* Flag to my_fopen for binary streams */
481
 
#endif
482
 
 
483
 
#define F_TO_EOF        0L      /* Param to lockf() to lock rest of file */
484
 
 
485
 
#ifndef O_TEMPORARY
486
 
#define O_TEMPORARY     0
487
 
#endif
488
 
#ifndef O_SHORT_LIVED
489
 
#define O_SHORT_LIVED   0
490
 
#endif
491
 
#ifndef O_NOFOLLOW
492
 
#define O_NOFOLLOW      0
493
 
#endif
494
 
 
495
 
/* #define USE_RECORD_LOCK      */
496
 
 
497
 
        /* Unsigned types supported by the compiler */
498
 
#define UNSINT8                 /* unsigned int8_t (char) */
499
 
#define UNSINT16                /* unsigned int16_t */
500
 
#define UNSINT32                /* unsigned int32_t */
501
 
 
502
 
        /* General constants */
503
 
#define SC_MAXWIDTH     256     /* Max width of screen (for error messages) */
504
 
#define FN_LEN          256     /* Max file name len */
505
 
#define FN_HEADLEN      253     /* Max length of filepart of file name */
506
 
#define FN_EXTLEN       20      /* Max length of extension (part of FN_LEN) */
507
 
#define FN_REFLEN       512     /* Max length of full path-name */
508
 
#define FN_EXTCHAR      '.'
509
 
#define FN_HOMELIB      '~'     /* ~/ is used as abbrev for home dir */
510
 
#define FN_CURLIB       '.'     /* ./ is used as abbrev for current dir */
511
 
#define FN_PARENTDIR    ".."    /* Parent directory; Must be a string */
 
176
 
512
177
 
513
178
#ifndef FN_LIBCHAR
514
 
#define FN_LIBCHAR      '/'
515
 
#define FN_ROOTDIR      "/"
 
179
#define FN_LIBCHAR  '/'
 
180
#define FN_ROOTDIR  "/"
516
181
#endif
517
 
#define MY_NFILE        64      /* This is only used to save filenames */
 
182
#define MY_NFILE  64  /* This is only used to save filenames */
518
183
#ifndef OS_FILE_LIMIT
519
 
#define OS_FILE_LIMIT   65535
 
184
#define OS_FILE_LIMIT  65535
520
185
#endif
521
186
 
522
 
/* #define EXT_IN_LIBNAME     */
523
 
/* #define FN_NO_CASE_SENCE   */
524
 
/* #define FN_UPPER_CASE TRUE */
525
 
 
526
 
/*
527
 
  Io buffer size; Must be a power of 2 and a multiple of 512. May be
528
 
  smaller what the disk page size. This influences the speed of the
529
 
  isam btree library. eg to big to slow.
530
 
*/
531
 
#define IO_SIZE                 4096
532
187
/*
533
188
  How much overhead does malloc have. The code often allocates
534
189
  something like 1024-MALLOC_OVERHEAD bytes
535
190
*/
536
191
#define MALLOC_OVERHEAD 8
537
192
 
538
 
        /* get memory in huncs */
539
 
#define ONCE_ALLOC_INIT         (uint) (4096-MALLOC_OVERHEAD)
540
 
        /* Typical record cash */
541
 
#define RECORD_CACHE_SIZE       (uint) (64*1024-MALLOC_OVERHEAD)
542
 
        /* Typical key cash */
543
 
#define KEY_CACHE_SIZE          (uint) (8*1024*1024-MALLOC_OVERHEAD)
544
 
        /* Default size of a key cache block  */
545
 
#define KEY_CACHE_BLOCK_SIZE    (uint) 1024
546
 
 
547
 
 
548
 
        /* Some things that this system doesn't have */
 
193
/* get memory in huncs */
 
194
static const uint32_t ONCE_ALLOC_INIT= 4096;
 
195
/* Typical record cash */
 
196
static const uint32_t RECORD_CACHE_SIZE= 64*1024;
 
197
/* Typical key cash */
 
198
static const uint32_t KEY_CACHE_SIZE= 8*1024*1024;
 
199
 
 
200
/* Default size of a key cache block  */
 
201
static const uint32_t KEY_CACHE_BLOCK_SIZE= 1024;
 
202
 
 
203
 
 
204
/* Some things that this system doesn't have */
549
205
 
550
206
/* Some defines of functions for portability */
551
207
 
552
 
#undef remove           /* Crashes MySQL on SCO 5.0.0 */
 
208
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
553
209
#ifndef uint64_t2double
554
210
#define uint64_t2double(A) ((double) (uint64_t) (A))
555
211
#define my_off_t2double(A)  ((double) (my_off_t) (A))
559
215
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
560
216
#endif
561
217
#define ulong_to_double(X) ((double) (ulong) (X))
562
 
#define SET_STACK_SIZE(X)       /* Not needed on real machines */
563
218
 
564
219
#ifndef STACK_DIRECTION
565
220
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
566
221
#endif
567
222
 
568
 
#if !defined(HAVE_STRTOK_R)
569
 
#define strtok_r(A,B,C) strtok((A),(B))
570
 
#endif
571
 
 
572
223
#ifdef HAVE_FLOAT_H
573
224
#include <float.h>
574
225
#else
582
233
 
583
234
/* From limits.h instead */
584
235
#ifndef DBL_MIN
585
 
#define DBL_MIN         4.94065645841246544e-324
 
236
#define DBL_MIN    4.94065645841246544e-324
586
237
#endif
587
238
#ifndef DBL_MAX
588
 
#define DBL_MAX         1.79769313486231470e+308
 
239
#define DBL_MAX    1.79769313486231470e+308
589
240
#endif
590
241
#ifndef SIZE_T_MAX
591
242
#define SIZE_T_MAX ~((size_t) 0)
592
243
#endif
593
244
 
594
 
#ifndef isfinite
595
 
#ifdef HAVE_FINITE
596
 
#define isfinite(x) finite(x)
597
 
#else
598
 
#define finite(x) (1.0 / fabs(x) > 0.0)
599
 
#endif /* HAVE_FINITE */
600
 
#endif /* isfinite */
601
 
 
602
 
#ifndef HAVE_ISNAN
603
 
#define isnan(x) ((x) != (x))
604
 
#endif
605
 
 
606
 
#ifdef HAVE_ISINF
607
 
/* isinf() can be used in both C and C++ code */
608
 
#define my_isinf(X) isinf(X)
609
 
#else
610
 
#define my_isinf(X) (!isfinite(X) && !isnan(X))
611
 
#endif
612
245
 
613
246
/* Define missing math constants. */
614
247
#ifndef M_PI
625
258
  Max size that must be added to a so that we know Size to make
626
259
  adressable obj.
627
260
*/
628
 
#if SIZEOF_CHARP == 4
629
 
typedef int32_t         my_ptrdiff_t;
630
 
#else
631
 
typedef int64_t         my_ptrdiff_t;
632
 
#endif
 
261
typedef ptrdiff_t my_ptrdiff_t;
633
262
 
634
 
#define MY_ALIGN(A,L)   (((A) + (L) - 1) & ~((L) - 1))
635
 
#define ALIGN_SIZE(A)   MY_ALIGN((A),sizeof(double))
 
263
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
 
264
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
636
265
/* Size to make adressable obj. */
637
266
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
638
 
                         /* Offset of field f in structure t */
639
 
#define OFFSET(t, f)    ((size_t)(char *)&((t *)0)->f)
640
 
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
641
 
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
 
267
/* Offset of field f in structure t */
 
268
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
 
269
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
 
270
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
642
271
 
643
272
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
644
273
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
645
274
 
646
 
/*
647
 
  Custom version of standard offsetof() macro which can be used to get
648
 
  offsets of members in class for non-POD types (according to the current
649
 
  version of C++ standard offsetof() macro can't be used in such cases and
650
 
  attempt to do so causes warnings to be emitted, OTOH in many cases it is
651
 
  still OK to assume that all instances of the class has the same offsets
652
 
  for the same members).
653
 
 
654
 
  This is temporary solution which should be removed once File_parser class
655
 
  and related routines are refactored.
656
 
*/
657
 
 
658
 
#define my_offsetof(TYPE, MEMBER) \
659
 
        ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
660
 
 
661
 
#define NullS           (char *) 0
662
 
 
663
275
/* Typdefs for easyier portability */
664
276
 
665
 
#ifndef HAVE_UCHAR
666
 
typedef unsigned char   uchar;  /* Short for unsigned char */
667
 
#endif
668
 
 
669
277
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
670
 
typedef unsigned long ulong;              /* Short for unsigned long */
 
278
typedef unsigned long ulong;      /* Short for unsigned long */
671
279
#endif
672
280
 
673
 
#define MY_ERRPTR ((void*)(intptr)1)
674
 
 
675
 
#if SIZEOF_OFF_T > 4 
676
281
typedef uint64_t my_off_t;
677
 
#else
678
 
typedef unsigned long my_off_t;
679
 
#endif 
680
 
#define MY_FILEPOS_ERROR        (~(my_off_t) 0)
681
 
 
682
 
typedef off_t os_off_t;
683
 
 
684
 
#define socket_errno    errno
685
 
#define SOCKET_EINTR    EINTR
686
 
#define SOCKET_EAGAIN   EAGAIN
687
 
#define SOCKET_ETIMEDOUT SOCKET_EINTR
688
 
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
689
 
#define SOCKET_EADDRINUSE EADDRINUSE
690
 
#define SOCKET_ENFILE   ENFILE
691
 
#define SOCKET_EMFILE   EMFILE
692
 
 
693
 
typedef uint8_t         int7;   /* Most effective integer 0 <= x <= 127 */
694
 
typedef short           int15;  /* Most effective integer 0 <= x <= 32767 */
695
 
typedef int             myf;    /* Type of MyFlags in my_funcs */
696
 
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
697
 
typedef char            bool;   /* Ordinary boolean values 0 1 */
 
282
 
 
283
#if defined(SIZEOF_OFF_T)
 
284
# if (SIZEOF_OFF_T == 8)
 
285
#  define OFF_T_MAX (INT64_MAX)
 
286
# else
 
287
#  define OFF_T_MAX (INT32_MAX)
 
288
# endif
698
289
#endif
699
 
        /* Macros for converting *constants* to the right type */
700
 
#define INT8(v)         (int8_t) (v)
701
 
#define INT16(v)        (int16_t) (v)
702
 
#define INT32(v)        (int32_t) (v)
703
 
#define MYF(v)          (myf) (v)
 
290
 
 
291
#define MY_FILEPOS_ERROR  -1
704
292
 
705
293
/* Defines for time function */
706
 
#define SCALE_SEC       100
707
 
#define SCALE_USEC      10000
708
 
#define MY_HOW_OFTEN_TO_ALARM   2       /* How often we want info on screen */
709
 
#define MY_HOW_OFTEN_TO_WRITE   1000    /* How often we want info on screen */
710
 
 
711
 
 
712
 
 
713
 
/*
714
 
  Define-funktions for reading and storing in machine independent format
715
 
  (low byte first)
716
 
*/
717
 
 
718
 
/* Optimized store functions for Intel x86 */
719
 
#if defined(__i386__)
720
 
#define sint2korr(A)    (*((int16_t *) (A)))
721
 
#define sint3korr(A)    ((int32_t) ((((uchar) (A)[2]) & 128) ? \
722
 
                                  (((uint32_t) 255L << 24) | \
723
 
                                   (((uint32_t) (uchar) (A)[2]) << 16) |\
724
 
                                   (((uint32_t) (uchar) (A)[1]) << 8) | \
725
 
                                   ((uint32_t) (uchar) (A)[0])) : \
726
 
                                  (((uint32_t) (uchar) (A)[2]) << 16) |\
727
 
                                  (((uint32_t) (uchar) (A)[1]) << 8) | \
728
 
                                  ((uint32_t) (uchar) (A)[0])))
729
 
#define sint4korr(A)    (*((long *) (A)))
730
 
#define uint2korr(A)    (*((uint16_t *) (A)))
731
 
#if defined(HAVE_purify)
732
 
#define uint3korr(A)    (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
733
 
                                  (((uint32_t) ((uchar) (A)[1])) << 8) +\
734
 
                                  (((uint32_t) ((uchar) (A)[2])) << 16))
735
 
#else
736
 
/*
737
 
   ATTENTION !
738
 
   
739
 
    Please, note, uint3korr reads 4 bytes (not 3) !
740
 
    It means, that you have to provide enough allocated space !
741
 
*/
742
 
#define uint3korr(A)    (long) (*((unsigned int *) (A)) & 0xFFFFFF)
743
 
#endif /* HAVE_purify */
744
 
#define uint4korr(A)    (*((uint32_t *) (A)))
745
 
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
746
 
                                    (((uint32_t) ((uchar) (A)[1])) << 8) +\
747
 
                                    (((uint32_t) ((uchar) (A)[2])) << 16) +\
748
 
                                    (((uint32_t) ((uchar) (A)[3])) << 24)) +\
749
 
                                    (((uint64_t) ((uchar) (A)[4])) << 32))
750
 
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((uchar) (A)[0]))          + \
751
 
                                     (((uint32_t)    ((uchar) (A)[1])) << 8)   + \
752
 
                                     (((uint32_t)    ((uchar) (A)[2])) << 16)  + \
753
 
                                     (((uint32_t)    ((uchar) (A)[3])) << 24)) + \
754
 
                         (((uint64_t) ((uchar) (A)[4])) << 32) +       \
755
 
                         (((uint64_t) ((uchar) (A)[5])) << 40))
756
 
#define uint8korr(A)    (*((uint64_t *) (A)))
757
 
#define sint8korr(A)    (*((int64_t *) (A)))
758
 
#define int2store(T,A)  *((uint16_t*) (T))= (uint16_t) (A)
759
 
#define int3store(T,A)  do { *(T)=  (uchar) ((A));\
760
 
                            *(T+1)=(uchar) (((uint) (A) >> 8));\
761
 
                            *(T+2)=(uchar) (((A) >> 16)); } while (0)
762
 
#define int4store(T,A)  *((long *) (T))= (long) (A)
763
 
#define int5store(T,A)  do { *(T)= (uchar)((A));\
764
 
                             *((T)+1)=(uchar) (((A) >> 8));\
765
 
                             *((T)+2)=(uchar) (((A) >> 16));\
766
 
                             *((T)+3)=(uchar) (((A) >> 24)); \
767
 
                             *((T)+4)=(uchar) (((A) >> 32)); } while(0)
768
 
#define int6store(T,A)  do { *(T)=    (uchar)((A));          \
769
 
                             *((T)+1)=(uchar) (((A) >> 8));  \
770
 
                             *((T)+2)=(uchar) (((A) >> 16)); \
771
 
                             *((T)+3)=(uchar) (((A) >> 24)); \
772
 
                             *((T)+4)=(uchar) (((A) >> 32)); \
773
 
                             *((T)+5)=(uchar) (((A) >> 40)); } while(0)
774
 
#define int8store(T,A)  *((uint64_t *) (T))= (uint64_t) (A)
775
 
 
776
 
typedef union {
777
 
  double v;
778
 
  long m[2];
779
 
} doubleget_union;
780
 
#define doubleget(V,M)  \
781
 
do { doubleget_union _tmp; \
782
 
     _tmp.m[0] = *((long*)(M)); \
783
 
     _tmp.m[1] = *(((long*) (M))+1); \
784
 
     (V) = _tmp.v; } while(0)
785
 
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
786
 
                             *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
787
 
                         } while (0)
788
 
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
789
 
#define float8get(V,M)   doubleget((V),(M))
790
 
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
791
 
#define floatstore(T,V)  memcpy((T), (&V), sizeof(float))
792
 
#define floatget(V,M)    memcpy(&V, (M), sizeof(float))
793
 
#define float8store(V,M) doublestore((V),(M))
794
 
#else
795
 
 
796
 
/*
797
 
  We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
798
 
  were done before)
799
 
*/
800
 
#define sint2korr(A)    (int16_t) (((int16_t) ((uchar) (A)[0])) +\
801
 
                                 ((int16_t) ((int16_t) (A)[1]) << 8))
802
 
#define sint3korr(A)    ((int32_t) ((((uchar) (A)[2]) & 128) ? \
803
 
                                  (((uint32_t) 255L << 24) | \
804
 
                                   (((uint32_t) (uchar) (A)[2]) << 16) |\
805
 
                                   (((uint32_t) (uchar) (A)[1]) << 8) | \
806
 
                                   ((uint32_t) (uchar) (A)[0])) : \
807
 
                                  (((uint32_t) (uchar) (A)[2]) << 16) |\
808
 
                                  (((uint32_t) (uchar) (A)[1]) << 8) | \
809
 
                                  ((uint32_t) (uchar) (A)[0])))
810
 
#define sint4korr(A)    (int32_t) (((int32_t) ((uchar) (A)[0])) +\
811
 
                                (((int32_t) ((uchar) (A)[1]) << 8)) +\
812
 
                                (((int32_t) ((uchar) (A)[2]) << 16)) +\
813
 
                                (((int32_t) ((int16_t) (A)[3]) << 24)))
814
 
#define sint8korr(A)    (int64_t) uint8korr(A)
815
 
#define uint2korr(A)    (uint16_t) (((uint16_t) ((uchar) (A)[0])) +\
816
 
                                  ((uint16_t) ((uchar) (A)[1]) << 8))
817
 
#define uint3korr(A)    (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
818
 
                                  (((uint32_t) ((uchar) (A)[1])) << 8) +\
819
 
                                  (((uint32_t) ((uchar) (A)[2])) << 16))
820
 
#define uint4korr(A)    (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
821
 
                                  (((uint32_t) ((uchar) (A)[1])) << 8) +\
822
 
                                  (((uint32_t) ((uchar) (A)[2])) << 16) +\
823
 
                                  (((uint32_t) ((uchar) (A)[3])) << 24))
824
 
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
825
 
                                    (((uint32_t) ((uchar) (A)[1])) << 8) +\
826
 
                                    (((uint32_t) ((uchar) (A)[2])) << 16) +\
827
 
                                    (((uint32_t) ((uchar) (A)[3])) << 24)) +\
828
 
                                    (((uint64_t) ((uchar) (A)[4])) << 32))
829
 
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((uchar) (A)[0]))          + \
830
 
                                     (((uint32_t)    ((uchar) (A)[1])) << 8)   + \
831
 
                                     (((uint32_t)    ((uchar) (A)[2])) << 16)  + \
832
 
                                     (((uint32_t)    ((uchar) (A)[3])) << 24)) + \
833
 
                         (((uint64_t) ((uchar) (A)[4])) << 32) +       \
834
 
                         (((uint64_t) ((uchar) (A)[5])) << 40))
835
 
#define uint8korr(A)    ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
836
 
                                    (((uint32_t) ((uchar) (A)[1])) << 8) +\
837
 
                                    (((uint32_t) ((uchar) (A)[2])) << 16) +\
838
 
                                    (((uint32_t) ((uchar) (A)[3])) << 24)) +\
839
 
                        (((uint64_t) (((uint32_t) ((uchar) (A)[4])) +\
840
 
                                    (((uint32_t) ((uchar) (A)[5])) << 8) +\
841
 
                                    (((uint32_t) ((uchar) (A)[6])) << 16) +\
842
 
                                    (((uint32_t) ((uchar) (A)[7])) << 24))) <<\
843
 
                                    32))
844
 
#define int2store(T,A)       do { uint def_temp= (uint) (A) ;\
845
 
                                  *((uchar*) (T))=  (uchar)(def_temp); \
846
 
                                   *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
847
 
                             } while(0)
848
 
#define int3store(T,A)       do { /*lint -save -e734 */\
849
 
                                  *((uchar*)(T))=(uchar) ((A));\
850
 
                                  *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
851
 
                                  *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
852
 
                                  /*lint -restore */} while(0)
853
 
#define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
854
 
                                  *(((char *)(T))+1)=(char) (((A) >> 8));\
855
 
                                  *(((char *)(T))+2)=(char) (((A) >> 16));\
856
 
                                  *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
857
 
#define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \
858
 
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
859
 
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
860
 
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
861
 
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
862
 
                                } while(0)
863
 
#define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \
864
 
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
865
 
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
866
 
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
867
 
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
868
 
                                  *(((char *)(T))+5)= (char)(((A) >> 40)); \
869
 
                                } while(0)
870
 
#define int8store(T,A)       do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
871
 
                                  int4store((T),def_temp); \
872
 
                                  int4store((T+4),def_temp2); } while(0)
873
 
#ifdef WORDS_BIGENDIAN
874
 
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
875
 
                              *((T)+1)=(char) ((uchar *) &A)[2];\
876
 
                              *((T)+2)=(char) ((uchar *) &A)[1];\
877
 
                              *((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
878
 
 
879
 
#define float4get(V,M)   do { float def_temp;\
880
 
                              ((uchar*) &def_temp)[0]=(M)[3];\
881
 
                              ((uchar*) &def_temp)[1]=(M)[2];\
882
 
                              ((uchar*) &def_temp)[2]=(M)[1];\
883
 
                              ((uchar*) &def_temp)[3]=(M)[0];\
884
 
                              (V)=def_temp; } while(0)
885
 
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
886
 
                              *((T)+1)=(char) ((uchar *) &V)[6];\
887
 
                              *((T)+2)=(char) ((uchar *) &V)[5];\
888
 
                              *((T)+3)=(char) ((uchar *) &V)[4];\
889
 
                              *((T)+4)=(char) ((uchar *) &V)[3];\
890
 
                              *((T)+5)=(char) ((uchar *) &V)[2];\
891
 
                              *((T)+6)=(char) ((uchar *) &V)[1];\
892
 
                              *((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
893
 
 
894
 
#define float8get(V,M)   do { double def_temp;\
895
 
                              ((uchar*) &def_temp)[0]=(M)[7];\
896
 
                              ((uchar*) &def_temp)[1]=(M)[6];\
897
 
                              ((uchar*) &def_temp)[2]=(M)[5];\
898
 
                              ((uchar*) &def_temp)[3]=(M)[4];\
899
 
                              ((uchar*) &def_temp)[4]=(M)[3];\
900
 
                              ((uchar*) &def_temp)[5]=(M)[2];\
901
 
                              ((uchar*) &def_temp)[6]=(M)[1];\
902
 
                              ((uchar*) &def_temp)[7]=(M)[0];\
903
 
                              (V) = def_temp; } while(0)
904
 
#else
905
 
#define float4get(V,M)   memcpy(&V, (M), sizeof(float))
906
 
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
907
 
 
908
 
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
909
 
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
910
 
                              *(((char*)T)+1)=(char) ((uchar *) &V)[5];\
911
 
                              *(((char*)T)+2)=(char) ((uchar *) &V)[6];\
912
 
                              *(((char*)T)+3)=(char) ((uchar *) &V)[7];\
913
 
                              *(((char*)T)+4)=(char) ((uchar *) &V)[0];\
914
 
                              *(((char*)T)+5)=(char) ((uchar *) &V)[1];\
915
 
                              *(((char*)T)+6)=(char) ((uchar *) &V)[2];\
916
 
                              *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
917
 
                         while(0)
918
 
#define doubleget(V,M)   do { double def_temp;\
919
 
                              ((uchar*) &def_temp)[0]=(M)[4];\
920
 
                              ((uchar*) &def_temp)[1]=(M)[5];\
921
 
                              ((uchar*) &def_temp)[2]=(M)[6];\
922
 
                              ((uchar*) &def_temp)[3]=(M)[7];\
923
 
                              ((uchar*) &def_temp)[4]=(M)[0];\
924
 
                              ((uchar*) &def_temp)[5]=(M)[1];\
925
 
                              ((uchar*) &def_temp)[6]=(M)[2];\
926
 
                              ((uchar*) &def_temp)[7]=(M)[3];\
927
 
                              (V) = def_temp; } while(0)
928
 
#endif /* __FLOAT_WORD_ORDER */
929
 
 
930
 
#define float8get(V,M)   doubleget((V),(M))
931
 
#define float8store(V,M) doublestore((V),(M))
932
 
#endif /* WORDS_BIGENDIAN */
933
 
 
934
 
#endif /* __i386__ */
935
 
 
936
 
/*
937
 
  Macro for reading 32-bit integer from network byte order (big-endian)
938
 
  from unaligned memory location.
939
 
*/
940
 
#define int4net(A)        (int32_t) (((uint32_t) ((uchar) (A)[3]))        |\
941
 
                                  (((uint32_t) ((uchar) (A)[2])) << 8)  |\
942
 
                                  (((uint32_t) ((uchar) (A)[1])) << 16) |\
943
 
                                  (((uint32_t) ((uchar) (A)[0])) << 24))
944
 
/*
945
 
  Define-funktions for reading and storing in machine format from/to
946
 
  short/long to/from some place in memory V should be a (not
947
 
  register) variable, M is a pointer to byte
948
 
*/
949
 
 
950
 
#ifdef WORDS_BIGENDIAN
951
 
 
952
 
#define ushortget(V,M)  do { V = (uint16_t) (((uint16_t) ((uchar) (M)[1]))+\
953
 
                                 ((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
954
 
#define shortget(V,M)   do { V = (short) (((short) ((uchar) (M)[1]))+\
955
 
                                 ((short) ((short) (M)[0]) << 8)); } while(0)
956
 
#define longget(V,M)    do { int32_t def_temp;\
957
 
                             ((uchar*) &def_temp)[0]=(M)[0];\
958
 
                             ((uchar*) &def_temp)[1]=(M)[1];\
959
 
                             ((uchar*) &def_temp)[2]=(M)[2];\
960
 
                             ((uchar*) &def_temp)[3]=(M)[3];\
961
 
                             (V)=def_temp; } while(0)
962
 
#define ulongget(V,M)   do { uint32_t def_temp;\
963
 
                            ((uchar*) &def_temp)[0]=(M)[0];\
964
 
                            ((uchar*) &def_temp)[1]=(M)[1];\
965
 
                            ((uchar*) &def_temp)[2]=(M)[2];\
966
 
                            ((uchar*) &def_temp)[3]=(M)[3];\
967
 
                            (V)=def_temp; } while(0)
968
 
#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
969
 
                             *(((char*)T)+1)=(char)(def_temp); \
970
 
                             *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
971
 
#define longstore(T,A)  do { *(((char*)T)+3)=((A));\
972
 
                             *(((char*)T)+2)=(((A) >> 8));\
973
 
                             *(((char*)T)+1)=(((A) >> 16));\
974
 
                             *(((char*)T)+0)=(((A) >> 24)); } while(0)
975
 
 
976
 
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
977
 
#define floatstore(T, V)   memcpy((T), (&V), sizeof(float))
978
 
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
979
 
#define doublestore(T, V)  memcpy((T), &V, sizeof(double))
980
 
#define int64_tget(V, M)   memcpy(&V, (M), sizeof(uint64_t))
981
 
#define int64_tstore(T, V) memcpy((T), &V, sizeof(uint64_t))
982
 
 
983
 
#else
984
 
 
985
 
#define ushortget(V,M)  do { V = uint2korr(M); } while(0)
986
 
#define shortget(V,M)   do { V = sint2korr(M); } while(0)
987
 
#define longget(V,M)    do { V = sint4korr(M); } while(0)
988
 
#define ulongget(V,M)   do { V = uint4korr(M); } while(0)
989
 
#define shortstore(T,V) int2store(T,V)
990
 
#define longstore(T,V)  int4store(T,V)
991
 
#ifndef floatstore
992
 
#define floatstore(T,V)   memcpy((T), (&V), sizeof(float))
993
 
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
994
 
#endif
995
 
#ifndef doubleget
996
 
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
997
 
#define doublestore(T,V)  memcpy((T), &V, sizeof(double))
998
 
#endif /* doubleget */
999
 
#define int64_tget(V,M)   memcpy(&V, (M), sizeof(uint64_t))
1000
 
#define int64_tstore(T,V) memcpy((T), &V, sizeof(uint64_t))
1001
 
 
1002
 
#endif /* WORDS_BIGENDIAN */
1003
 
 
1004
 
/* my_sprintf  was here. RIP */
1005
 
 
1006
 
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
1007
 
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
1008
 
#else
1009
 
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
1010
 
#endif
 
294
#define SCALE_SEC  100
 
295
#define SCALE_USEC  10000
 
296
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
 
297
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
 
298
 
1011
299
 
1012
300
#include <dlfcn.h>
1013
301
 
1016
304
#define RTLD_NOW 1
1017
305
#endif
1018
306
 
1019
 
/*
1020
 
 *  Include standard definitions of operator new and delete.
1021
 
 */
1022
 
#ifdef __cplusplus
1023
 
#include <new>
1024
 
#include <string>
1025
 
#include <algorithm>
1026
 
using namespace std;
1027
 
#endif
1028
 
#define max(a, b)       ((a) > (b) ? (a) : (b))
1029
 
#define min(a, b)       ((a) < (b) ? (a) : (b))
 
307
#define DRIZZLE_SERVER
1030
308
 
1031
309
/* Length of decimal number represented by INT32. */
1032
310
#define MY_INT32_NUM_DECIMAL_DIGITS 11
1035
313
#define MY_INT64_NUM_DECIMAL_DIGITS 21
1036
314
 
1037
315
/*
 
316
  Io buffer size; Must be a power of 2 and
 
317
  a multiple of 512. May be
 
318
  smaller what the disk page size. This influences the speed of the
 
319
  isam btree library. eg to big to slow.
 
320
*/
 
321
#define IO_SIZE 4096
 
322
/* Max file name len */
 
323
#define FN_LEN 256
 
324
/* Max length of extension (part of FN_LEN) */
 
325
#define FN_EXTLEN 20
 
326
/* Max length of full path-name */
 
327
#define FN_REFLEN 512
 
328
/* File extension character */
 
329
#define FN_EXTCHAR '.'
 
330
/* ~ is used as abbrev for home dir */
 
331
#define FN_HOMELIB '~'
 
332
/* ./ is used as abbrev for current dir */
 
333
#define FN_CURLIB '.'
 
334
/* Parent directory; Must be a string */
 
335
#define FN_PARENTDIR ".."
 
336
 
 
337
/* Quote argument (before cpp) */
 
338
#ifndef QUOTE_ARG
 
339
# define QUOTE_ARG(x) #x
 
340
#endif
 
341
/* Quote argument, (after cpp) */
 
342
#ifndef STRINGIFY_ARG
 
343
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
 
344
#endif
 
345
 
 
346
/*
 
347
 * The macros below are borrowed from include/linux/compiler.h in the
 
348
 * Linux kernel. Use them to indicate the likelyhood of the truthfulness
 
349
 * of a condition. This serves two purposes - newer versions of gcc will be
 
350
 * able to optimize for branch predication, which could yield siginficant
 
351
 * performance gains in frequently executed sections of the code, and the
 
352
 * other reason to use them is for documentation
 
353
 */
 
354
#if !defined(__GNUC__)
 
355
#define __builtin_expect(x, expected_value) (x)
 
356
#endif
 
357
 
 
358
#define likely(x)  __builtin_expect((x),1)
 
359
#define unlikely(x)  __builtin_expect((x),0)
 
360
 
 
361
 
 
362
/*
1038
363
  Only Linux is known to need an explicit sync of the directory to make sure a
1039
364
  file creation/deletion/renaming in(from,to) this directory durable.
1040
365
*/
1042
367
#define NEED_EXPLICIT_SYNC_DIR 1
1043
368
#endif
1044
369
 
1045
 
#include <libdrizzle/gettext.h>
 
370
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
 
371
#if !defined(HAVE_DTRACE)
 
372
# undef _DTRACE_VERSION
 
373
# define _DTRACE_VERSION 0
 
374
#endif
1046
375
 
1047
376
#endif /* DRIZZLE_SERVER_GLOBAL_H */