~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
212.5.45 by Monty Taylor
Removed excess AM_CPPFLAGS from the tree. Now the only thing that should be in the include path should be -I${top_srcdir} and -I${top_builddir}w
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 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
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
61
/*
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
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
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
71
#endif */ /* TIME_WITH_SYS_TIME */
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.
72
1 by brian
clean slate
73
/*
74
  Temporary solution to solve bug#7156. Include "sys/types.h" before
75
  the thread headers, else the function madvise() will not be defined
76
*/
77
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
78
#include <sys/types.h>
79
#endif
80
316 by Brian Aker
First pass of new sql_db.cc work
81
398.1.10 by Monty Taylor
Actually removed VOID() this time.
82
#include <pthread.h>    /* AIX must have this included first */
83
84
#define _REENTRANT  1  /* Threads requires reentrant code */
1 by brian
clean slate
85
86
#ifdef HAVE_LIMITS_H
87
#include <limits.h>
88
#endif
89
90
#ifdef HAVE_SYS_TYPES_H
91
#include <sys/types.h>
92
#endif
93
#ifdef HAVE_FCNTL_H
94
#include <fcntl.h>
95
#endif
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
96
1 by brian
clean slate
97
#ifdef HAVE_UNISTD_H
98
#include <unistd.h>
99
#endif
100
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
101
#undef HAVE_ALLOCA
102
#undef HAVE_ALLOCA_H
103
#endif
104
#ifdef HAVE_ALLOCA_H
105
#include <alloca.h>
106
#endif
107
108
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
109
236.1.12 by Monty Taylor
Add global include of sys/stat.h.
110
#ifdef HAVE_SYS_STAT_H
111
# include <sys/stat.h>
112
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
113
1 by brian
clean slate
114
#if !defined(HAVE_UINT)
115
#undef HAVE_UINT
116
#define HAVE_UINT
117
typedef unsigned int uint;
118
#endif
119
240.1.6 by Toru Maesaka
removed mystring dependencies from libdrizzle.c
120
/* Declared in int2str() */
121
extern char _dig_vec_upper[];
122
extern char _dig_vec_lower[];
123
1 by brian
clean slate
124
#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.
125
1 by brian
clean slate
126
#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.
127
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
1 by brian
clean slate
128
129
/* Some types that is different between systems */
130
398.1.10 by Monty Taylor
Actually removed VOID() this time.
131
typedef int  File;    /* File descriptor */
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
132
1 by brian
clean slate
133
#ifdef HAVE_SYS_SOCKET_H
134
#include <sys/socket.h>
135
#endif
136
137
/* file create flags */
138
139
#ifndef O_TEMPORARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
140
#define O_TEMPORARY  0
1 by brian
clean slate
141
#endif
142
#ifndef O_SHORT_LIVED
398.1.10 by Monty Taylor
Actually removed VOID() this time.
143
#define O_SHORT_LIVED  0
1 by brian
clean slate
144
#endif
145
#ifndef O_NOFOLLOW
146
#define O_NOFOLLOW      0
147
#endif
148
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
149
1 by brian
clean slate
150
151
#ifndef FN_LIBCHAR
398.1.10 by Monty Taylor
Actually removed VOID() this time.
152
#define FN_LIBCHAR  '/'
153
#define FN_ROOTDIR  "/"
1 by brian
clean slate
154
#endif
398.1.10 by Monty Taylor
Actually removed VOID() this time.
155
#define MY_NFILE  64  /* This is only used to save filenames */
1 by brian
clean slate
156
#ifndef OS_FILE_LIMIT
398.1.10 by Monty Taylor
Actually removed VOID() this time.
157
#define OS_FILE_LIMIT  65535
1 by brian
clean slate
158
#endif
159
160
/*
161
  How much overhead does malloc have. The code often allocates
162
  something like 1024-MALLOC_OVERHEAD bytes
163
*/
164
#define MALLOC_OVERHEAD 8
165
398.1.10 by Monty Taylor
Actually removed VOID() this time.
166
/* get memory in huncs */
167
#define ONCE_ALLOC_INIT    (uint) (4096-MALLOC_OVERHEAD)
168
/* Typical record cash */
169
#define RECORD_CACHE_SIZE  (uint) (64*1024-MALLOC_OVERHEAD)
170
/* Typical key cash */
171
#define KEY_CACHE_SIZE    (uint) (8*1024*1024-MALLOC_OVERHEAD)
172
/* Default size of a key cache block  */
173
#define KEY_CACHE_BLOCK_SIZE  (uint) 1024
174
175
176
/* Some things that this system doesn't have */
1 by brian
clean slate
177
178
/* Some defines of functions for portability */
179
398.1.10 by Monty Taylor
Actually removed VOID() this time.
180
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
151 by Brian Aker
Ulonglong to uint64_t
181
#ifndef uint64_t2double
182
#define uint64_t2double(A) ((double) (uint64_t) (A))
1 by brian
clean slate
183
#define my_off_t2double(A)  ((double) (my_off_t) (A))
184
#endif
185
186
#ifndef offsetof
187
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
188
#endif
189
#define ulong_to_double(X) ((double) (ulong) (X))
190
191
#ifndef STACK_DIRECTION
192
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
193
#endif
194
195
#if !defined(HAVE_STRTOK_R)
196
#define strtok_r(A,B,C) strtok((A),(B))
197
#endif
198
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
199
#ifdef HAVE_FLOAT_H
200
#include <float.h>
201
#else
202
#if !defined(FLT_MIN)
203
#define FLT_MIN         ((float)1.40129846432481707e-45)
204
#endif
205
#if !defined(FLT_MAX)
206
#define FLT_MAX         ((float)3.40282346638528860e+38)
207
#endif
208
#endif
209
1 by brian
clean slate
210
/* From limits.h instead */
211
#ifndef DBL_MIN
398.1.10 by Monty Taylor
Actually removed VOID() this time.
212
#define DBL_MIN    4.94065645841246544e-324
1 by brian
clean slate
213
#endif
214
#ifndef DBL_MAX
398.1.10 by Monty Taylor
Actually removed VOID() this time.
215
#define DBL_MAX    1.79769313486231470e+308
1 by brian
clean slate
216
#endif
217
#ifndef SIZE_T_MAX
218
#define SIZE_T_MAX ~((size_t) 0)
219
#endif
220
221
222
/* Define missing math constants. */
223
#ifndef M_PI
224
#define M_PI 3.14159265358979323846
225
#endif
226
#ifndef M_E
227
#define M_E 2.7182818284590452354
228
#endif
229
#ifndef M_LN2
230
#define M_LN2 0.69314718055994530942
231
#endif
232
233
/*
234
  Max size that must be added to a so that we know Size to make
235
  adressable obj.
236
*/
481.1.21 by Monty Taylor
Got rid of some size testing.
237
typedef ptrdiff_t my_ptrdiff_t;
1 by brian
clean slate
238
398.1.10 by Monty Taylor
Actually removed VOID() this time.
239
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
240
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
1 by brian
clean slate
241
/* Size to make adressable obj. */
242
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
398.1.10 by Monty Taylor
Actually removed VOID() this time.
243
/* Offset of field f in structure t */
244
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
481 by Brian Aker
Remove all of uchar.
245
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
246
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
1 by brian
clean slate
247
248
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
249
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
250
251
/* Typdefs for easyier portability */
252
253
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
254
typedef unsigned long ulong;      /* Short for unsigned long */
1 by brian
clean slate
255
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
256
151 by Brian Aker
Ulonglong to uint64_t
257
typedef uint64_t my_off_t;
1 by brian
clean slate
258
489.1.13 by Monty Taylor
One step closer to simpler off_t support.
259
#define MY_FILEPOS_ERROR  (UINT64_MAX)
1 by brian
clean slate
260
398.1.10 by Monty Taylor
Actually removed VOID() this time.
261
typedef int    myf;  /* Type of MyFlags in my_funcs */
1 by brian
clean slate
262
#define MYF(v)		(myf) (v)
263
264
/* Defines for time function */
398.1.10 by Monty Taylor
Actually removed VOID() this time.
265
#define SCALE_SEC  100
266
#define SCALE_USEC  10000
267
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
268
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
1 by brian
clean slate
269
270
271
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
272
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
1 by brian
clean slate
273
#else
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
274
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
1 by brian
clean slate
275
#endif
276
277
#include <dlfcn.h>
278
279
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
280
#ifndef RTLD_NOW
281
#define RTLD_NOW 1
282
#endif
283
398.1.4 by Monty Taylor
Renamed max/min.
284
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
285
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
1 by brian
clean slate
286
287
/* Length of decimal number represented by INT32. */
288
#define MY_INT32_NUM_DECIMAL_DIGITS 11
289
290
/* Length of decimal number represented by INT64. */
291
#define MY_INT64_NUM_DECIMAL_DIGITS 21
292
293
/*
294
  Only Linux is known to need an explicit sync of the directory to make sure a
295
  file creation/deletion/renaming in(from,to) this directory durable.
296
*/
297
#ifdef TARGET_OS_LINUX
298
#define NEED_EXPLICIT_SYNC_DIR 1
299
#endif
300
202.3.5 by Monty Taylor
Giant merge.
301
#include <libdrizzle/gettext.h>
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
302
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
303
#endif /* DRIZZLE_SERVER_GLOBAL_H */