~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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 by brian
clean slate
19
20
/* This is the include file that should be included 'first' in every C file. */
21
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
22
#ifndef DRIZZLE_SERVER_GLOBAL_H
23
#define DRIZZLE_SERVER_GLOBAL_H
1 by brian
clean slate
24
25
#if defined(i386) && !defined(__i386__)
26
#define __i386__
27
#endif
28
549 by Monty Taylor
Took gettext.h out of header files.
29
#include <config.h>
1 by brian
clean slate
30
481.1.9 by Monty Taylor
Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.
31
#if defined(__cplusplus)
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
32
33
# if defined(__GNUC) && defined(__EXCEPTIONS)
34
#  error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
35
# endif
36
481.1.9 by Monty Taylor
Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.
37
# include CSTDINT_H
38
# include CINTTYPES_H
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
39
# include <cstdio>
40
# include <cstdlib>
41
# include <cstddef>
42
# include <cassert>
43
# include <cerrno>
670.1.11 by Monty Taylor
Merged from Toru.
44
# include <sstream>
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
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
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
61
#ifndef EOVERFLOW
62
#define EOVERFLOW 84
63
#endif
64
815.1.6 by Monty Taylor
Some tweaks to get timegm working on Solaris.
65
779.3.47 by Monty Taylor
Fixed solaris fixes on linux.
66
#if TIME_WITH_SYS_TIME
67
# include <sys/time.h>
68
# include <time.h>
69
#else
70
# if HAVE_SYS_TIME_H
71
#  include <sys/time.h>
72
# else
73
#  include <time.h>
74
# endif
75
#endif
76
#ifndef HAVE_DECL_TIMEGM
779.3.45 by Monty Taylor
Fixed temporal on solaris the right way this time.
77
#include <gnulib/time.h>
78
# if defined(__cplusplus)
79
extern "C"
815.1.6 by Monty Taylor
Some tweaks to get timegm working on Solaris.
80
# endif
779.3.45 by Monty Taylor
Fixed temporal on solaris the right way this time.
81
time_t timegm (struct tm *__tm);
82
#endif /* HAVE_DECL_TIMEGM */
815.1.6 by Monty Taylor
Some tweaks to get timegm working on Solaris.
83
84
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
85
/*
1 by brian
clean slate
86
  Temporary solution to solve bug#7156. Include "sys/types.h" before
87
  the thread headers, else the function madvise() will not be defined
88
*/
89
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
90
#include <sys/types.h>
91
#endif
92
316 by Brian Aker
First pass of new sql_db.cc work
93
398.1.10 by Monty Taylor
Actually removed VOID() this time.
94
#include <pthread.h>    /* AIX must have this included first */
95
96
#define _REENTRANT  1  /* Threads requires reentrant code */
1 by brian
clean slate
97
98
#ifdef HAVE_LIMITS_H
99
#include <limits.h>
100
#endif
101
102
#ifdef HAVE_SYS_TYPES_H
103
#include <sys/types.h>
104
#endif
105
#ifdef HAVE_FCNTL_H
106
#include <fcntl.h>
107
#endif
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
108
1 by brian
clean slate
109
#ifdef HAVE_UNISTD_H
110
#include <unistd.h>
111
#endif
112
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
113
236.1.12 by Monty Taylor
Add global include of sys/stat.h.
114
#ifdef HAVE_SYS_STAT_H
115
# include <sys/stat.h>
116
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
117
1 by brian
clean slate
118
#if !defined(HAVE_UINT)
119
#undef HAVE_UINT
120
#define HAVE_UINT
121
typedef unsigned int uint;
122
#endif
123
240.1.6 by Toru Maesaka
removed mystring dependencies from libdrizzle.c
124
/* Declared in int2str() */
125
extern char _dig_vec_upper[];
126
extern char _dig_vec_lower[];
127
1 by brian
clean slate
128
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
465 by Monty Taylor
Made a few macros into template functions.
129
1 by brian
clean slate
130
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
465 by Monty Taylor
Made a few macros into template functions.
131
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
1 by brian
clean slate
132
133
/* Some types that is different between systems */
134
398.1.10 by Monty Taylor
Actually removed VOID() this time.
135
typedef int  File;    /* File descriptor */
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
136
1 by brian
clean slate
137
#ifdef HAVE_SYS_SOCKET_H
138
#include <sys/socket.h>
139
#endif
140
141
142
#ifndef FN_LIBCHAR
398.1.10 by Monty Taylor
Actually removed VOID() this time.
143
#define FN_LIBCHAR  '/'
144
#define FN_ROOTDIR  "/"
1 by brian
clean slate
145
#endif
398.1.10 by Monty Taylor
Actually removed VOID() this time.
146
#define MY_NFILE  64  /* This is only used to save filenames */
1 by brian
clean slate
147
#ifndef OS_FILE_LIMIT
398.1.10 by Monty Taylor
Actually removed VOID() this time.
148
#define OS_FILE_LIMIT  65535
1 by brian
clean slate
149
#endif
150
151
/*
152
  How much overhead does malloc have. The code often allocates
153
  something like 1024-MALLOC_OVERHEAD bytes
154
*/
155
#define MALLOC_OVERHEAD 8
156
398.1.10 by Monty Taylor
Actually removed VOID() this time.
157
/* get memory in huncs */
158
#define ONCE_ALLOC_INIT    (uint) (4096-MALLOC_OVERHEAD)
159
/* Typical record cash */
160
#define RECORD_CACHE_SIZE  (uint) (64*1024-MALLOC_OVERHEAD)
161
/* Typical key cash */
162
#define KEY_CACHE_SIZE    (uint) (8*1024*1024-MALLOC_OVERHEAD)
163
/* Default size of a key cache block  */
164
#define KEY_CACHE_BLOCK_SIZE  (uint) 1024
165
166
167
/* Some things that this system doesn't have */
1 by brian
clean slate
168
169
/* Some defines of functions for portability */
170
398.1.10 by Monty Taylor
Actually removed VOID() this time.
171
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
151 by Brian Aker
Ulonglong to uint64_t
172
#ifndef uint64_t2double
173
#define uint64_t2double(A) ((double) (uint64_t) (A))
1 by brian
clean slate
174
#define my_off_t2double(A)  ((double) (my_off_t) (A))
175
#endif
176
177
#ifndef offsetof
178
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
179
#endif
180
#define ulong_to_double(X) ((double) (ulong) (X))
181
182
#ifndef STACK_DIRECTION
183
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
184
#endif
185
186
#if !defined(HAVE_STRTOK_R)
187
#define strtok_r(A,B,C) strtok((A),(B))
188
#endif
189
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
190
#ifdef HAVE_FLOAT_H
191
#include <float.h>
192
#else
193
#if !defined(FLT_MIN)
194
#define FLT_MIN         ((float)1.40129846432481707e-45)
195
#endif
196
#if !defined(FLT_MAX)
197
#define FLT_MAX         ((float)3.40282346638528860e+38)
198
#endif
199
#endif
200
1 by brian
clean slate
201
/* From limits.h instead */
202
#ifndef DBL_MIN
398.1.10 by Monty Taylor
Actually removed VOID() this time.
203
#define DBL_MIN    4.94065645841246544e-324
1 by brian
clean slate
204
#endif
205
#ifndef DBL_MAX
398.1.10 by Monty Taylor
Actually removed VOID() this time.
206
#define DBL_MAX    1.79769313486231470e+308
1 by brian
clean slate
207
#endif
208
#ifndef SIZE_T_MAX
209
#define SIZE_T_MAX ~((size_t) 0)
210
#endif
211
212
213
/* Define missing math constants. */
214
#ifndef M_PI
215
#define M_PI 3.14159265358979323846
216
#endif
217
#ifndef M_E
218
#define M_E 2.7182818284590452354
219
#endif
220
#ifndef M_LN2
221
#define M_LN2 0.69314718055994530942
222
#endif
223
224
/*
225
  Max size that must be added to a so that we know Size to make
226
  adressable obj.
227
*/
481.1.21 by Monty Taylor
Got rid of some size testing.
228
typedef ptrdiff_t my_ptrdiff_t;
1 by brian
clean slate
229
398.1.10 by Monty Taylor
Actually removed VOID() this time.
230
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
231
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
1 by brian
clean slate
232
/* Size to make adressable obj. */
233
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
398.1.10 by Monty Taylor
Actually removed VOID() this time.
234
/* Offset of field f in structure t */
235
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
481 by Brian Aker
Remove all of uchar.
236
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
237
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
1 by brian
clean slate
238
239
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
240
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
241
242
/* Typdefs for easyier portability */
243
244
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
245
typedef unsigned long ulong;      /* Short for unsigned long */
1 by brian
clean slate
246
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
247
151 by Brian Aker
Ulonglong to uint64_t
248
typedef uint64_t my_off_t;
1 by brian
clean slate
249
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
250
#if defined(SIZEOF_OFF_T)
251
# if (SIZEOF_OFF_T == 8)
252
#  define OFF_T_MAX (INT64_MAX)
253
# else
254
#  define OFF_T_MAX (INT32_MAX)
255
# endif
256
#endif
1 by brian
clean slate
257
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
258
#define MY_FILEPOS_ERROR  -1
1 by brian
clean slate
259
260
/* Defines for time function */
398.1.10 by Monty Taylor
Actually removed VOID() this time.
261
#define SCALE_SEC  100
262
#define SCALE_USEC  10000
263
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
264
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
1 by brian
clean slate
265
266
267
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
268
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
1 by brian
clean slate
269
#else
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
270
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
1 by brian
clean slate
271
#endif
272
273
#include <dlfcn.h>
274
275
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
276
#ifndef RTLD_NOW
277
#define RTLD_NOW 1
278
#endif
279
398.1.4 by Monty Taylor
Renamed max/min.
280
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
281
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
1 by brian
clean slate
282
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
283
#define DRIZZLE_SERVER
284
1 by brian
clean slate
285
/* Length of decimal number represented by INT32. */
286
#define MY_INT32_NUM_DECIMAL_DIGITS 11
287
288
/* Length of decimal number represented by INT64. */
289
#define MY_INT64_NUM_DECIMAL_DIGITS 21
290
722.1.3 by Monty Taylor
Cleaned up a few build things.
291
#define PROTOCOL_VERSION 10
292
/*
293
  Io buffer size; Must be a power of 2 and
294
  a multiple of 512. May be
295
  smaller what the disk page size. This influences the speed of the
296
  isam btree library. eg to big to slow.
297
*/
298
#define IO_SIZE 4096
299
/* Max file name len */
300
#define FN_LEN 256
301
/* Max length of extension (part of FN_LEN) */
302
#define FN_EXTLEN 20
303
/* Max length of full path-name */
304
#define FN_REFLEN 512
305
/* File extension character */
306
#define FN_EXTCHAR '.'
307
/* ~ is used as abbrev for home dir */
308
#define FN_HOMELIB '~'
309
/* ./ is used as abbrev for current dir */
310
#define FN_CURLIB '.'
311
/* Parent directory; Must be a string */
312
#define FN_PARENTDIR ".."
313
314
/* Quote argument (before cpp) */
315
#ifndef QUOTE_ARG
316
# define QUOTE_ARG(x) #x
317
#endif
318
/* Quote argument, (after cpp) */
319
#ifndef STRINGIFY_ARG
320
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
321
#endif
322
323
/*
324
 * The macros below are borrowed from include/linux/compiler.h in the
325
 * Linux kernel. Use them to indicate the likelyhood of the truthfulness
326
 * of a condition. This serves two purposes - newer versions of gcc will be
327
 * able to optimize for branch predication, which could yield siginficant
328
 * performance gains in frequently executed sections of the code, and the
329
 * other reason to use them is for documentation
330
 */
331
#if !defined(__GNUC__)
332
#define __builtin_expect(x, expected_value) (x)
333
#endif
334
335
#define likely(x)  __builtin_expect((x),1)
336
#define unlikely(x)  __builtin_expect((x),0)
337
338
1 by brian
clean slate
339
/*
340
  Only Linux is known to need an explicit sync of the directory to make sure a
341
  file creation/deletion/renaming in(from,to) this directory durable.
342
*/
343
#ifdef TARGET_OS_LINUX
344
#define NEED_EXPLICIT_SYNC_DIR 1
345
#endif
346
520.4.43 by mordred
A set of Solaris fixes.
347
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
348
#if !defined(HAVE_DTRACE)
349
# undef _DTRACE_VERSION
350
# define _DTRACE_VERSION 0
351
#endif
352
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
353
#endif /* DRIZZLE_SERVER_GLOBAL_H */