~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
465 by Monty Taylor
Made a few macros into template functions.
124
#if defined(__cplusplus)
125
template <class T>
126
inline bool test(const T a)
127
{
128
  return a ? true : false;
129
}
130
template <class T, class U>
131
inline bool test_all_bits(const T a, const U b)
132
{
133
  return ((a & b) == b);
134
}
135
#else
398.1.10 by Monty Taylor
Actually removed VOID() this time.
136
#define test(a)    ((a) ? 1 : 0)
465 by Monty Taylor
Made a few macros into template functions.
137
#define test_all_bits(a,b) (((a) & (b)) == (b))
138
#endif
139
1 by brian
clean slate
140
#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.
141
1 by brian
clean slate
142
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
143
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
465 by Monty Taylor
Made a few macros into template functions.
144
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
1 by brian
clean slate
145
146
/* Some types that is different between systems */
147
398.1.10 by Monty Taylor
Actually removed VOID() this time.
148
typedef int  File;    /* File descriptor */
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
149
1 by brian
clean slate
150
#ifdef HAVE_SYS_SOCKET_H
151
#include <sys/socket.h>
152
#endif
153
154
/* file create flags */
155
398.1.10 by Monty Taylor
Actually removed VOID() this time.
156
#ifndef O_SHARE      /* Probably not windows */
157
#define O_SHARE    0  /* Flag to my_open for shared files */
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
158
#endif /* O_SHARE */
159
1 by brian
clean slate
160
#ifndef O_BINARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
161
#define O_BINARY  0  /* Flag to my_open for binary files */
1 by brian
clean slate
162
#endif
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
163
1 by brian
clean slate
164
#ifndef FILE_BINARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
165
#define FILE_BINARY  O_BINARY /* Flag to my_fopen for binary streams */
1 by brian
clean slate
166
#endif
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
167
398.1.10 by Monty Taylor
Actually removed VOID() this time.
168
#define F_TO_EOF  0L  /* Param to lockf() to lock rest of file */
1 by brian
clean slate
169
170
#ifndef O_TEMPORARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
171
#define O_TEMPORARY  0
1 by brian
clean slate
172
#endif
173
#ifndef O_SHORT_LIVED
398.1.10 by Monty Taylor
Actually removed VOID() this time.
174
#define O_SHORT_LIVED  0
1 by brian
clean slate
175
#endif
176
#ifndef O_NOFOLLOW
177
#define O_NOFOLLOW      0
178
#endif
179
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...
180
1 by brian
clean slate
181
182
#ifndef FN_LIBCHAR
398.1.10 by Monty Taylor
Actually removed VOID() this time.
183
#define FN_LIBCHAR  '/'
184
#define FN_ROOTDIR  "/"
1 by brian
clean slate
185
#endif
398.1.10 by Monty Taylor
Actually removed VOID() this time.
186
#define MY_NFILE  64  /* This is only used to save filenames */
1 by brian
clean slate
187
#ifndef OS_FILE_LIMIT
398.1.10 by Monty Taylor
Actually removed VOID() this time.
188
#define OS_FILE_LIMIT  65535
1 by brian
clean slate
189
#endif
190
191
/*
192
  How much overhead does malloc have. The code often allocates
193
  something like 1024-MALLOC_OVERHEAD bytes
194
*/
195
#define MALLOC_OVERHEAD 8
196
398.1.10 by Monty Taylor
Actually removed VOID() this time.
197
/* get memory in huncs */
198
#define ONCE_ALLOC_INIT    (uint) (4096-MALLOC_OVERHEAD)
199
/* Typical record cash */
200
#define RECORD_CACHE_SIZE  (uint) (64*1024-MALLOC_OVERHEAD)
201
/* Typical key cash */
202
#define KEY_CACHE_SIZE    (uint) (8*1024*1024-MALLOC_OVERHEAD)
203
/* Default size of a key cache block  */
204
#define KEY_CACHE_BLOCK_SIZE  (uint) 1024
205
206
207
/* Some things that this system doesn't have */
1 by brian
clean slate
208
209
/* Some defines of functions for portability */
210
398.1.10 by Monty Taylor
Actually removed VOID() this time.
211
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
151 by Brian Aker
Ulonglong to uint64_t
212
#ifndef uint64_t2double
213
#define uint64_t2double(A) ((double) (uint64_t) (A))
1 by brian
clean slate
214
#define my_off_t2double(A)  ((double) (my_off_t) (A))
215
#endif
216
217
#ifndef offsetof
218
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
219
#endif
220
#define ulong_to_double(X) ((double) (ulong) (X))
221
222
#ifndef STACK_DIRECTION
223
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
224
#endif
225
226
#if !defined(HAVE_STRTOK_R)
227
#define strtok_r(A,B,C) strtok((A),(B))
228
#endif
229
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
230
#ifdef HAVE_FLOAT_H
231
#include <float.h>
232
#else
233
#if !defined(FLT_MIN)
234
#define FLT_MIN         ((float)1.40129846432481707e-45)
235
#endif
236
#if !defined(FLT_MAX)
237
#define FLT_MAX         ((float)3.40282346638528860e+38)
238
#endif
239
#endif
240
1 by brian
clean slate
241
/* From limits.h instead */
242
#ifndef DBL_MIN
398.1.10 by Monty Taylor
Actually removed VOID() this time.
243
#define DBL_MIN    4.94065645841246544e-324
1 by brian
clean slate
244
#endif
245
#ifndef DBL_MAX
398.1.10 by Monty Taylor
Actually removed VOID() this time.
246
#define DBL_MAX    1.79769313486231470e+308
1 by brian
clean slate
247
#endif
248
#ifndef SIZE_T_MAX
249
#define SIZE_T_MAX ~((size_t) 0)
250
#endif
251
252
253
/* Define missing math constants. */
254
#ifndef M_PI
255
#define M_PI 3.14159265358979323846
256
#endif
257
#ifndef M_E
258
#define M_E 2.7182818284590452354
259
#endif
260
#ifndef M_LN2
261
#define M_LN2 0.69314718055994530942
262
#endif
263
264
/*
265
  Max size that must be added to a so that we know Size to make
266
  adressable obj.
267
*/
268
#if SIZEOF_CHARP == 4
398.1.10 by Monty Taylor
Actually removed VOID() this time.
269
typedef int32_t    my_ptrdiff_t;
1 by brian
clean slate
270
#else
398.1.10 by Monty Taylor
Actually removed VOID() this time.
271
typedef int64_t   my_ptrdiff_t;
1 by brian
clean slate
272
#endif
273
398.1.10 by Monty Taylor
Actually removed VOID() this time.
274
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
275
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
1 by brian
clean slate
276
/* Size to make adressable obj. */
277
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
398.1.10 by Monty Taylor
Actually removed VOID() this time.
278
/* Offset of field f in structure t */
279
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
481 by Brian Aker
Remove all of uchar.
280
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
281
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
1 by brian
clean slate
282
283
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
284
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
285
286
/* Typdefs for easyier portability */
287
288
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
289
typedef unsigned long ulong;      /* Short for unsigned long */
1 by brian
clean slate
290
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
291
77.1.103 by Monty Taylor
Fixed some format strings to use PRIu64 for the uint64_t types.
292
#if SIZEOF_OFF_T > 4 
151 by Brian Aker
Ulonglong to uint64_t
293
typedef uint64_t my_off_t;
1 by brian
clean slate
294
#else
295
typedef unsigned long my_off_t;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
296
#endif
297
#define MY_FILEPOS_ERROR  (~(my_off_t) 0)
1 by brian
clean slate
298
299
typedef off_t os_off_t;
300
398.1.10 by Monty Taylor
Actually removed VOID() this time.
301
typedef int    myf;  /* Type of MyFlags in my_funcs */
1 by brian
clean slate
302
#define MYF(v)		(myf) (v)
303
304
/* Defines for time function */
398.1.10 by Monty Taylor
Actually removed VOID() this time.
305
#define SCALE_SEC  100
306
#define SCALE_USEC  10000
307
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
308
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
1 by brian
clean slate
309
310
311
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
312
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
1 by brian
clean slate
313
#else
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
314
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
1 by brian
clean slate
315
#endif
316
317
#include <dlfcn.h>
318
319
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
320
#ifndef RTLD_NOW
321
#define RTLD_NOW 1
322
#endif
323
398.1.4 by Monty Taylor
Renamed max/min.
324
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
325
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
1 by brian
clean slate
326
327
/* Length of decimal number represented by INT32. */
328
#define MY_INT32_NUM_DECIMAL_DIGITS 11
329
330
/* Length of decimal number represented by INT64. */
331
#define MY_INT64_NUM_DECIMAL_DIGITS 21
332
333
/*
334
  Only Linux is known to need an explicit sync of the directory to make sure a
335
  file creation/deletion/renaming in(from,to) this directory durable.
336
*/
337
#ifdef TARGET_OS_LINUX
338
#define NEED_EXPLICIT_SYNC_DIR 1
339
#endif
340
202.3.5 by Monty Taylor
Giant merge.
341
#include <libdrizzle/gettext.h>
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
342
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
343
#endif /* DRIZZLE_SERVER_GLOBAL_H */