~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
31
/*
32
  Temporary solution to solve bug#7156. Include "sys/types.h" before
33
  the thread headers, else the function madvise() will not be defined
34
*/
35
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
36
#include <sys/types.h>
37
#endif
38
316 by Brian Aker
First pass of new sql_db.cc work
39
#if defined(HAVE_STDINT_H)
421 by Monty
Made including stdint.h work.
40
#include <stdint.h>
41
#else
42
#error "You must have stdint!"
43
#endif
44
45
#if defined(HAVE_INTTYPES_H)
316 by Brian Aker
First pass of new sql_db.cc work
46
#include <inttypes.h>
319 by Brian Aker
Fix (yuck!) for OSX/Google bug.
47
#else
48
#error "You must have inttypes!"
316 by Brian Aker
First pass of new sql_db.cc work
49
#endif
50
398.1.10 by Monty Taylor
Actually removed VOID() this time.
51
#include <pthread.h>    /* AIX must have this included first */
52
53
#define _REENTRANT  1  /* Threads requires reentrant code */
1 by brian
clean slate
54
55
56
/* gcc/egcs issues */
57
58
#if defined(__GNUC) && defined(__EXCEPTIONS)
59
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
60
#endif
61
62
#ifndef stdin
63
#include <stdio.h>
64
#endif
65
#ifdef HAVE_STDLIB_H
66
#include <stdlib.h>
67
#endif
68
#ifdef HAVE_STDDEF_H
69
#include <stddef.h>
70
#endif
71
72
#include <math.h>
73
#ifdef HAVE_LIMITS_H
74
#include <limits.h>
75
#endif
76
77
#ifdef HAVE_SYS_TYPES_H
78
#include <sys/types.h>
79
#endif
80
#ifdef HAVE_FCNTL_H
81
#include <fcntl.h>
82
#endif
83
#ifdef HAVE_SYS_TIMEB_H
398.1.10 by Monty Taylor
Actually removed VOID() this time.
84
#include <sys/timeb.h>        /* Avoid warnings on SCO */
1 by brian
clean slate
85
#endif
86
#if TIME_WITH_SYS_TIME
87
# include <sys/time.h>
88
# include <time.h>
89
#else
90
# if HAVE_SYS_TIME_H
91
#  include <sys/time.h>
92
# else
93
#  include <time.h>
94
# endif
95
#endif /* TIME_WITH_SYS_TIME */
96
#ifdef HAVE_UNISTD_H
97
#include <unistd.h>
98
#endif
99
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
100
#undef HAVE_ALLOCA
101
#undef HAVE_ALLOCA_H
102
#endif
103
#ifdef HAVE_ALLOCA_H
104
#include <alloca.h>
105
#endif
106
398.1.10 by Monty Taylor
Actually removed VOID() this time.
107
#include <errno.h>        /* Recommended by debian */
1 by brian
clean slate
108
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
109
#if defined(HAVE_STDBOOL_H)
110
#include <stdbool.h>
111
#endif
112
236.1.12 by Monty Taylor
Add global include of sys/stat.h.
113
#ifdef HAVE_SYS_STAT_H
114
# include <sys/stat.h>
115
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
116
1 by brian
clean slate
117
/*
118
  A lot of our programs uses asserts, so better to always include it
119
*/
120
#include <assert.h>
121
122
/* an assert that works at compile-time. only for constant expression */
123
#ifndef __GNUC__
124
#define compile_time_assert(X)  do { } while(0)
125
#else
126
#define compile_time_assert(X)                                  \
127
  do                                                            \
128
  {                                                             \
129
    char compile_time_assert[(X) ? 1 : -1]                      \
398.1.10 by Monty Taylor
Actually removed VOID() this time.
130
      __attribute__ ((unused));                                 \
1 by brian
clean slate
131
  } while(0)
132
#endif
133
134
/* Declare madvise where it is not declared for C++, like Solaris */
392 by Monty Taylor
Fixed a small compile problem.
135
#if defined(HAVE_MADVISE) && !defined(HAVE_DECL_MADVISE) && defined(__cplusplus)
1 by brian
clean slate
136
extern "C" int madvise(void *addr, size_t len, int behav);
137
#endif
138
139
#if !defined(HAVE_UINT)
140
#undef HAVE_UINT
141
#define HAVE_UINT
142
typedef unsigned int uint;
143
typedef unsigned short ushort;
144
#endif
145
240.1.6 by Toru Maesaka
removed mystring dependencies from libdrizzle.c
146
/* Declared in int2str() */
147
extern char _dig_vec_upper[];
148
extern char _dig_vec_lower[];
149
398.1.10 by Monty Taylor
Actually removed VOID() this time.
150
#define test(a)    ((a) ? 1 : 0)
1 by brian
clean slate
151
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
152
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
153
#define test_all_bits(a,b) (((a) & (b)) == (b))
154
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
155
#define array_elements(A) ((uint32_t) (sizeof(A)/sizeof(A[0])))
1 by brian
clean slate
156
157
/* Some types that is different between systems */
158
398.1.10 by Monty Taylor
Actually removed VOID() this time.
159
typedef int  File;    /* File descriptor */
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
160
161
#ifdef __cplusplus
162
extern "C" {
163
#endif
164
165
  typedef void (*sig_return)(void);/* Returns type from signal */
166
  typedef int  (*qsort_cmp)(const void *,const void *);
167
  typedef int  (*qsort_cmp2)(void*, const void *,const void *);
168
169
#ifdef __cplusplus
170
}
171
#endif
172
1 by brian
clean slate
173
#ifdef HAVE_SYS_SOCKET_H
174
#include <sys/socket.h>
175
#endif
176
typedef SOCKET_SIZE_TYPE size_socket;
177
178
#ifndef SOCKOPT_OPTLEN_TYPE
179
#define SOCKOPT_OPTLEN_TYPE size_socket
180
#endif
181
182
/* file create flags */
183
398.1.10 by Monty Taylor
Actually removed VOID() this time.
184
#ifndef O_SHARE      /* Probably not windows */
185
#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.
186
#endif /* O_SHARE */
187
1 by brian
clean slate
188
#ifndef O_BINARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
189
#define O_BINARY  0  /* Flag to my_open for binary files */
1 by brian
clean slate
190
#endif
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
191
1 by brian
clean slate
192
#ifndef FILE_BINARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
193
#define FILE_BINARY  O_BINARY /* Flag to my_fopen for binary streams */
1 by brian
clean slate
194
#endif
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
195
398.1.10 by Monty Taylor
Actually removed VOID() this time.
196
#define F_TO_EOF  0L  /* Param to lockf() to lock rest of file */
1 by brian
clean slate
197
198
#ifndef O_TEMPORARY
398.1.10 by Monty Taylor
Actually removed VOID() this time.
199
#define O_TEMPORARY  0
1 by brian
clean slate
200
#endif
201
#ifndef O_SHORT_LIVED
398.1.10 by Monty Taylor
Actually removed VOID() this time.
202
#define O_SHORT_LIVED  0
1 by brian
clean slate
203
#endif
204
#ifndef O_NOFOLLOW
205
#define O_NOFOLLOW      0
206
#endif
207
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...
208
1 by brian
clean slate
209
210
#ifndef FN_LIBCHAR
398.1.10 by Monty Taylor
Actually removed VOID() this time.
211
#define FN_LIBCHAR  '/'
212
#define FN_ROOTDIR  "/"
1 by brian
clean slate
213
#endif
398.1.10 by Monty Taylor
Actually removed VOID() this time.
214
#define MY_NFILE  64  /* This is only used to save filenames */
1 by brian
clean slate
215
#ifndef OS_FILE_LIMIT
398.1.10 by Monty Taylor
Actually removed VOID() this time.
216
#define OS_FILE_LIMIT  65535
1 by brian
clean slate
217
#endif
218
219
/*
220
  How much overhead does malloc have. The code often allocates
221
  something like 1024-MALLOC_OVERHEAD bytes
222
*/
223
#define MALLOC_OVERHEAD 8
224
398.1.10 by Monty Taylor
Actually removed VOID() this time.
225
/* get memory in huncs */
226
#define ONCE_ALLOC_INIT    (uint) (4096-MALLOC_OVERHEAD)
227
/* Typical record cash */
228
#define RECORD_CACHE_SIZE  (uint) (64*1024-MALLOC_OVERHEAD)
229
/* Typical key cash */
230
#define KEY_CACHE_SIZE    (uint) (8*1024*1024-MALLOC_OVERHEAD)
231
/* Default size of a key cache block  */
232
#define KEY_CACHE_BLOCK_SIZE  (uint) 1024
233
234
235
/* Some things that this system doesn't have */
1 by brian
clean slate
236
237
/* Some defines of functions for portability */
238
398.1.10 by Monty Taylor
Actually removed VOID() this time.
239
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
151 by Brian Aker
Ulonglong to uint64_t
240
#ifndef uint64_t2double
241
#define uint64_t2double(A) ((double) (uint64_t) (A))
1 by brian
clean slate
242
#define my_off_t2double(A)  ((double) (my_off_t) (A))
243
#endif
244
245
#ifndef offsetof
246
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
247
#endif
248
#define ulong_to_double(X) ((double) (ulong) (X))
249
250
#ifndef STACK_DIRECTION
251
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
252
#endif
253
254
#if !defined(HAVE_STRTOK_R)
255
#define strtok_r(A,B,C) strtok((A),(B))
256
#endif
257
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
258
#ifdef HAVE_FLOAT_H
259
#include <float.h>
260
#else
261
#if !defined(FLT_MIN)
262
#define FLT_MIN         ((float)1.40129846432481707e-45)
263
#endif
264
#if !defined(FLT_MAX)
265
#define FLT_MAX         ((float)3.40282346638528860e+38)
266
#endif
267
#endif
268
1 by brian
clean slate
269
/* From limits.h instead */
270
#ifndef DBL_MIN
398.1.10 by Monty Taylor
Actually removed VOID() this time.
271
#define DBL_MIN    4.94065645841246544e-324
1 by brian
clean slate
272
#endif
273
#ifndef DBL_MAX
398.1.10 by Monty Taylor
Actually removed VOID() this time.
274
#define DBL_MAX    1.79769313486231470e+308
1 by brian
clean slate
275
#endif
276
#ifndef SIZE_T_MAX
277
#define SIZE_T_MAX ~((size_t) 0)
278
#endif
279
280
281
/* Define missing math constants. */
282
#ifndef M_PI
283
#define M_PI 3.14159265358979323846
284
#endif
285
#ifndef M_E
286
#define M_E 2.7182818284590452354
287
#endif
288
#ifndef M_LN2
289
#define M_LN2 0.69314718055994530942
290
#endif
291
292
/*
293
  Max size that must be added to a so that we know Size to make
294
  adressable obj.
295
*/
296
#if SIZEOF_CHARP == 4
398.1.10 by Monty Taylor
Actually removed VOID() this time.
297
typedef int32_t    my_ptrdiff_t;
1 by brian
clean slate
298
#else
398.1.10 by Monty Taylor
Actually removed VOID() this time.
299
typedef int64_t   my_ptrdiff_t;
1 by brian
clean slate
300
#endif
301
398.1.10 by Monty Taylor
Actually removed VOID() this time.
302
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
303
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
1 by brian
clean slate
304
/* Size to make adressable obj. */
305
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
398.1.10 by Monty Taylor
Actually removed VOID() this time.
306
/* Offset of field f in structure t */
307
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
1 by brian
clean slate
308
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
309
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
310
311
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
312
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
313
314
/*
315
  Custom version of standard offsetof() macro which can be used to get
316
  offsets of members in class for non-POD types (according to the current
317
  version of C++ standard offsetof() macro can't be used in such cases and
318
  attempt to do so causes warnings to be emitted, OTOH in many cases it is
319
  still OK to assume that all instances of the class has the same offsets
320
  for the same members).
321
322
  This is temporary solution which should be removed once File_parser class
323
  and related routines are refactored.
324
*/
325
398.1.10 by Monty Taylor
Actually removed VOID() this time.
326
#define my_offsetof(TYPE, MEMBER)                                       \
327
  ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
1 by brian
clean slate
328
398.1.10 by Monty Taylor
Actually removed VOID() this time.
329
#define NullS    (char *) 0
1 by brian
clean slate
330
331
/* Typdefs for easyier portability */
332
333
#ifndef HAVE_UCHAR
398.1.10 by Monty Taylor
Actually removed VOID() this time.
334
typedef unsigned char  uchar;  /* Short for unsigned char */
1 by brian
clean slate
335
#endif
336
337
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
338
typedef unsigned long ulong;      /* Short for unsigned long */
1 by brian
clean slate
339
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
340
77.1.103 by Monty Taylor
Fixed some format strings to use PRIu64 for the uint64_t types.
341
#if SIZEOF_OFF_T > 4 
151 by Brian Aker
Ulonglong to uint64_t
342
typedef uint64_t my_off_t;
1 by brian
clean slate
343
#else
344
typedef unsigned long my_off_t;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
345
#endif
346
#define MY_FILEPOS_ERROR  (~(my_off_t) 0)
1 by brian
clean slate
347
348
typedef off_t os_off_t;
349
398.1.10 by Monty Taylor
Actually removed VOID() this time.
350
typedef int    myf;  /* Type of MyFlags in my_funcs */
1 by brian
clean slate
351
#define MYF(v)		(myf) (v)
352
353
/* Defines for time function */
398.1.10 by Monty Taylor
Actually removed VOID() this time.
354
#define SCALE_SEC  100
355
#define SCALE_USEC  10000
356
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
357
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
1 by brian
clean slate
358
359
360
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
361
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
1 by brian
clean slate
362
#else
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
363
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
1 by brian
clean slate
364
#endif
365
366
#include <dlfcn.h>
367
368
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
369
#ifndef RTLD_NOW
370
#define RTLD_NOW 1
371
#endif
372
398.1.4 by Monty Taylor
Renamed max/min.
373
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
374
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
1 by brian
clean slate
375
376
/* Length of decimal number represented by INT32. */
377
#define MY_INT32_NUM_DECIMAL_DIGITS 11
378
379
/* Length of decimal number represented by INT64. */
380
#define MY_INT64_NUM_DECIMAL_DIGITS 21
381
382
/*
383
  Only Linux is known to need an explicit sync of the directory to make sure a
384
  file creation/deletion/renaming in(from,to) this directory durable.
385
*/
386
#ifdef TARGET_OS_LINUX
387
#define NEED_EXPLICIT_SYNC_DIR 1
388
#endif
389
202.3.5 by Monty Taylor
Giant merge.
390
#include <libdrizzle/gettext.h>
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
391
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
392
#endif /* DRIZZLE_SERVER_GLOBAL_H */