~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

  • Committer: Brian Aker
  • Date: 2009-02-12 22:45:08 UTC
  • Revision ID: brian@tangent.org-20090212224508-mrd9jwgn1zjdpqdk
Minor refactoring (we will need to disconnect the code from the include
file).

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#define __i386__
27
27
#endif
28
28
 
29
 
#include "config.h"
 
29
#include <config.h>
 
30
 
 
31
#if defined(__cplusplus)
 
32
 
 
33
# if defined(__GNUC) && defined(__EXCEPTIONS)
 
34
#  error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
 
35
# endif
 
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
#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
 
 
61
#ifndef EOVERFLOW
 
62
#define EOVERFLOW 84
 
63
#endif
 
64
 
 
65
 
 
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
 
77
#include <gnulib/time.h>
 
78
# if defined(__cplusplus)
 
79
extern "C"
 
80
# endif
 
81
time_t timegm (struct tm *__tm);
 
82
#endif /* HAVE_DECL_TIMEGM */
 
83
 
30
84
 
31
85
/*
32
86
  Temporary solution to solve bug#7156. Include "sys/types.h" before
36
90
#include <sys/types.h>
37
91
#endif
38
92
 
39
 
#if defined(HAVE_STDINT_H)
40
 
#include <stdint.h>
41
 
#else
42
 
#error "You must have stdint!"
43
 
#endif
44
 
 
45
 
#if defined(HAVE_INTTYPES_H)
46
 
#include <inttypes.h>
47
 
#else
48
 
#error "You must have inttypes!"
49
 
#endif
50
93
 
51
94
#include <pthread.h>    /* AIX must have this included first */
52
95
 
53
96
#define _REENTRANT  1  /* Threads requires reentrant code */
54
97
 
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
98
#ifdef HAVE_LIMITS_H
74
99
#include <limits.h>
75
100
#endif
80
105
#ifdef HAVE_FCNTL_H
81
106
#include <fcntl.h>
82
107
#endif
83
 
#ifdef HAVE_SYS_TIMEB_H
84
 
#include <sys/timeb.h>        /* Avoid warnings on SCO */
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 */
 
108
 
96
109
#ifdef HAVE_UNISTD_H
97
110
#include <unistd.h>
98
111
#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
 
 
107
 
#include <errno.h>        /* Recommended by debian */
108
 
 
109
 
#if defined(HAVE_STDBOOL_H)
110
 
#include <stdbool.h>
111
 
#endif
 
112
 
112
113
 
113
114
#ifdef HAVE_SYS_STAT_H
114
115
# include <sys/stat.h>
115
116
#endif
116
117
 
117
 
/*
118
 
  A lot of our programs uses asserts, so better to always include it
119
 
*/
120
 
#include <assert.h>
121
 
 
122
118
#if !defined(HAVE_UINT)
123
119
#undef HAVE_UINT
124
120
#define HAVE_UINT
125
121
typedef unsigned int uint;
126
 
typedef unsigned short ushort;
127
122
#endif
128
123
 
129
124
/* Declared in int2str() */
130
125
extern char _dig_vec_upper[];
131
126
extern char _dig_vec_lower[];
132
127
 
133
 
#if defined(__cplusplus)
134
 
template <class T>
135
 
inline bool test(const T a)
136
 
{
137
 
  return a ? true : false;
138
 
}
139
 
template <class T, class U>
140
 
inline bool test_all_bits(const T a, const U b)
141
 
{
142
 
  return ((a & b) == b);
143
 
}
144
 
#else
145
 
#define test(a)    ((a) ? 1 : 0)
146
 
#define test_all_bits(a,b) (((a) & (b)) == (b))
147
 
#endif
148
 
 
149
128
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
150
129
 
151
130
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
152
 
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
153
131
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
154
132
 
155
133
/* Some types that is different between systems */
160
138
#include <sys/socket.h>
161
139
#endif
162
140
 
163
 
/* file create flags */
164
 
 
165
 
#ifndef O_SHARE      /* Probably not windows */
166
 
#define O_SHARE    0  /* Flag to my_open for shared files */
167
 
#endif /* O_SHARE */
168
 
 
169
 
#ifndef O_BINARY
170
 
#define O_BINARY  0  /* Flag to my_open for binary files */
171
 
#endif
172
 
 
173
 
#ifndef FILE_BINARY
174
 
#define FILE_BINARY  O_BINARY /* Flag to my_fopen for binary streams */
175
 
#endif
176
 
 
177
 
#define F_TO_EOF  0L  /* Param to lockf() to lock rest of file */
178
 
 
179
 
#ifndef O_TEMPORARY
180
 
#define O_TEMPORARY  0
181
 
#endif
182
 
#ifndef O_SHORT_LIVED
183
 
#define O_SHORT_LIVED  0
184
 
#endif
185
 
#ifndef O_NOFOLLOW
186
 
#define O_NOFOLLOW      0
187
 
#endif
188
 
 
189
 
 
190
141
 
191
142
#ifndef FN_LIBCHAR
192
143
#define FN_LIBCHAR  '/'
274
225
  Max size that must be added to a so that we know Size to make
275
226
  adressable obj.
276
227
*/
277
 
#if SIZEOF_CHARP == 4
278
 
typedef int32_t    my_ptrdiff_t;
279
 
#else
280
 
typedef int64_t   my_ptrdiff_t;
281
 
#endif
 
228
typedef ptrdiff_t my_ptrdiff_t;
282
229
 
283
230
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
284
231
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
298
245
typedef unsigned long ulong;      /* Short for unsigned long */
299
246
#endif
300
247
 
301
 
#if SIZEOF_OFF_T > 4 
302
248
typedef uint64_t my_off_t;
303
 
#else
304
 
typedef unsigned long my_off_t;
 
249
 
 
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
305
256
#endif
306
 
#define MY_FILEPOS_ERROR  (~(my_off_t) 0)
307
 
 
308
 
typedef off_t os_off_t;
309
 
 
310
 
typedef int    myf;  /* Type of MyFlags in my_funcs */
311
 
#define MYF(v)          (myf) (v)
 
257
 
 
258
#define MY_FILEPOS_ERROR  -1
312
259
 
313
260
/* Defines for time function */
314
261
#define SCALE_SEC  100
333
280
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
334
281
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
335
282
 
 
283
#define DRIZZLE_SERVER
 
284
 
336
285
/* Length of decimal number represented by INT32. */
337
286
#define MY_INT32_NUM_DECIMAL_DIGITS 11
338
287
 
339
288
/* Length of decimal number represented by INT64. */
340
289
#define MY_INT64_NUM_DECIMAL_DIGITS 21
341
290
 
 
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
 
342
339
/*
343
340
  Only Linux is known to need an explicit sync of the directory to make sure a
344
341
  file creation/deletion/renaming in(from,to) this directory durable.
347
344
#define NEED_EXPLICIT_SYNC_DIR 1
348
345
#endif
349
346
 
350
 
#include <libdrizzle/gettext.h>
 
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
351
352
 
352
353
#endif /* DRIZZLE_SERVER_GLOBAL_H */