~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSDefs.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
2
 
 *
3
 
 * PrimeBase Media Stream for MySQL
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
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
 
 *
19
 
 * Original author: Paul McCullagh (H&G2JCtL)
20
 
 * Continued development: Barry Leslie
21
 
 *
22
 
 * 2007-06-02
23
 
 *
24
 
 * CORE SYSTEM:
25
 
 * Common definitions that may be required be included at the
26
 
 * top of every header file.
27
 
 *
28
 
 */
29
 
 
30
 
#pragma once
31
 
#ifndef __CSDEFS_H__
32
 
#define __CSDEFS_H__
33
 
 
34
 
#include <sys/types.h>
35
 
 
36
 
// Use standard portable data types
37
 
#include <stdint.h>
38
 
 
39
 
/* Those compilers that support the function
40
 
 * macro (in particular the "pretty" function
41
 
 * macro must be defined here.
42
 
 */
43
 
#ifdef OS_WINDOWS
44
 
#define __FUNC__                                __FUNCTION__
45
 
#elif defined(OS_SOLARIS)
46
 
#define __FUNC__                                "__func__"
47
 
#else
48
 
#define __FUNC__                                __PRETTY_FUNCTION__
49
 
#endif
50
 
 
51
 
/*
52
 
 * An unsigned integer, 1 byte long:
53
 
 */
54
 
#ifndef u_char
55
 
#define u_char                  unsigned char
56
 
#endif
57
 
 
58
 
/*
59
 
 * An usigned integer, 1 byte long:
60
 
 */
61
 
#define s_char                  unsigned char
62
 
 
63
 
/* We assumes that off_t is 8 bytes so to ensure this always use  off64_t*/
64
 
#define off64_t                 uint64_t
65
 
 
66
 
 
67
 
/*
68
 
 * A signed integer at least 32 bits long.
69
 
 * The size used is whatever is most
70
 
 * convenient to the machine.
71
 
 */
72
 
#define s_int int_fast32_t
73
 
 
74
 
/* Forward declartion of a thread: */
75
 
class CSThread;
76
 
 
77
 
// Used to avoid warnings about unused parameters.
78
 
#define UNUSED(x) (void)x
79
 
 
80
 
#ifdef OS_WINDOWS
81
 
 
82
 
#define CS_DEFAULT_EOL          "\r\n"
83
 
#define CS_DIR_CHAR                     '\\'
84
 
#define CS_DIR_DELIM            "\\"
85
 
#define IS_DIR_CHAR(ch)         ((ch) == CS_DIR_CHAR || (ch) == '/')
86
 
 
87
 
#ifndef PATH_MAX
88
 
#define PATH_MAX                MAX_PATH
89
 
#endif
90
 
 
91
 
#ifndef NAME_MAX
92
 
#define NAME_MAX                MAX_PATH
93
 
#endif
94
 
 
95
 
#else
96
 
 
97
 
#define CS_DEFAULT_EOL          "\n"
98
 
#define CS_DIR_CHAR                     '/'
99
 
#define CS_DIR_DELIM            "/"
100
 
#define IS_DIR_CHAR(ch)         ((ch) == CS_DIR_CHAR)
101
 
 
102
 
#endif // OS_WINDOWS
103
 
 
104
 
#define CS_CALL_STACK_SIZE              100
105
 
#define CS_RELEASE_STACK_SIZE   200
106
 
#define CS_JUMP_STACK_SIZE              20      // NOTE: If a stack overflow occurs check that there are no returns inside of try_() blocks.
107
 
 
108
 
/* C string display width sizes including space for a null terminator and possible sign. */
109
 
#define CS_WIDTH_INT_8  5
110
 
#define CS_WIDTH_INT_16 7
111
 
#define CS_WIDTH_INT_32 12
112
 
#define CS_WIDTH_INT_64 22
113
 
 
114
 
typedef uint8_t                 CSDiskValue1[1];        
115
 
typedef uint8_t                 CSDiskValue2[2];        
116
 
typedef uint8_t                 CSDiskValue3[3];        
117
 
typedef uint8_t                 CSDiskValue4[4];        
118
 
typedef uint8_t                 CSDiskValue6[6];        
119
 
typedef uint8_t                 CSDiskValue8[8];        
120
 
 
121
 
/*
122
 
 * Byte order on the disk is little endian! This is the byte order of the i386.
123
 
 * Little endian byte order starts with the least significan byte.
124
 
 *
125
 
 * The reason for choosing this byte order for the disk is 2-fold:
126
 
 * Firstly the i386 is the cheapest and fasted platform today.
127
 
 * Secondly the i386, unlike RISK chips (with big endian) can address
128
 
 * memory that is not aligned!
129
 
 *
130
 
 * Since the disk image of PrimeBase XT is not aligned, the second point
131
 
 * is significant. A RISK chip needs to access it byte-wise, so we might as
132
 
 * well do the byte swapping at the same time.
133
 
 *
134
 
 * The macros below are of 4 general types:
135
 
 *
136
 
 * GET/SET - Get and set 1,2,4,8 byte values (short, int, long, etc).
137
 
 * Values are swapped only on big endian platforms. This makes these
138
 
 * functions very efficient on little-endian platforms.
139
 
 *
140
 
 * COPY - Transfer data without swapping regardless of platform. This
141
 
 * function is a bit more efficient on little-endian platforms
142
 
 * because alignment is not an issue.
143
 
 *
144
 
 * MOVE - Similar to get and set, but the deals with memory instead
145
 
 * of values. Since no swapping is done on little-endian platforms
146
 
 * this function is identical to COPY on little-endian platforms.
147
 
 *
148
 
 * SWAP - Transfer and swap data regardless of the platform type.
149
 
 * Aligment is not assumed.
150
 
 *
151
 
 * The DISK component of the macro names indicates that alignment of
152
 
 * the value cannot be assumed.
153
 
 *
154
 
 */
155
 
#if BYTE_ORDER == BIG_ENDIAN
156
 
/* The native order of the machine is big endian. Since the native disk
157
 
 * disk order of XT is little endian, all data to and from disk
158
 
 * must be swapped.
159
 
 */
160
 
#define CS_SET_DISK_1(d, s)             ((d)[0] = (uint8_t) (s))
161
 
 
162
 
#define CS_SET_DISK_2(d, s)             do { (d)[0] = (uint8_t)  (((uint16_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint16_t) (s)) >> 8 ) & 0xFF); } while (0)
163
 
 
164
 
#define CS_SET_DISK_3(d, s)             do { (d)[0] = (uint8_t)  (((uint32_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint32_t) (s)) >> 8 ) & 0xFF); \
165
 
                                                                         (d)[2] = (uint8_t) ((((uint32_t) (s)) >> 16) & 0xFF); } while (0)
166
 
 
167
 
#define CS_SET_DISK_4(d, s)             do { (d)[0] = (uint8_t)  (((uint32_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint32_t) (s)) >> 8 ) & 0xFF); \
168
 
                                                                         (d)[2] = (uint8_t) ((((uint32_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint32_t) (s)) >> 24) & 0xFF); } while (0)
169
 
 
170
 
#define CS_SET_DISK_6(d, s)             do { (d)[0] = (uint8_t)  (((uint64_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint64_t) (s)) >> 8 ) & 0xFF); \
171
 
                                                                         (d)[2] = (uint8_t) ((((uint64_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint64_t) (s)) >> 24) & 0xFF); \
172
 
                                                                         (d)[4] = (uint8_t) ((((uint64_t) (s)) >> 32) & 0xFF); (d)[5] = (uint8_t) ((((uint64_t) (s)) >> 40) & 0xFF); } while (0)
173
 
 
174
 
#define CS_SET_DISK_8(d, s)             do { (d)[0] = (uint8_t)  (((uint64_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint64_t) (s)) >> 8 ) & 0xFF); \
175
 
                                                                         (d)[2] = (uint8_t) ((((uint64_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint64_t) (s)) >> 24) & 0xFF); \
176
 
                                                                         (d)[4] = (uint8_t) ((((uint64_t) (s)) >> 32) & 0xFF); (d)[5] = (uint8_t) ((((uint64_t) (s)) >> 40) & 0xFF); \
177
 
                                                                         (d)[6] = (uint8_t) ((((uint64_t) (s)) >> 48) & 0xFF); (d)[7] = (uint8_t) ((((uint64_t) (s)) >> 56) & 0xFF); } while (0)
178
 
 
179
 
#define CS_GET_DISK_1(s)                ((s)[0])
180
 
 
181
 
#define CS_GET_DISK_2(s)                ((uint16_t) (((uint16_t) (s)[0]) | (((uint16_t) (s)[1]) << 8)))
182
 
 
183
 
#define CS_GET_DISK_3(s)                ((uint32_t) (((uint32_t) (s)[0]) | (((uint32_t) (s)[1]) << 8) | (((uint32_t) (s)[2]) << 16)))
184
 
 
185
 
#define CS_GET_DISK_4(s)                (((uint32_t) (s)[0])        | (((uint32_t) (s)[1]) << 8 ) | \
186
 
                                                                (((uint32_t) (s)[2]) << 16) | (((uint32_t) (s)[3]) << 24))
187
 
 
188
 
#define CS_GET_DISK_6(s)                (((uint64_t) (s)[0])        | (((uint64_t) (s)[1]) << 8 ) | \
189
 
                                                                (((uint64_t) (s)[2]) << 16) | (((uint64_t) (s)[3]) << 24) | \
190
 
                                                                (((uint64_t) (s)[4]) << 32) | (((uint64_t) (s)[5]) << 40))
191
 
 
192
 
#define CS_GET_DISK_8(s)                (((uint64_t) (s)[0])        | (((uint64_t) (s)[1]) << 8 ) | \
193
 
                                                                (((uint64_t) (s)[2]) << 16) | (((uint64_t) (s)[3]) << 24) | \
194
 
                                                                (((uint64_t) (s)[4]) << 32) | (((uint64_t) (s)[5]) << 40) | \
195
 
                                                                (((uint64_t) (s)[6]) << 48) | (((uint64_t) (s)[7]) << 56))
196
 
 
197
 
/* Move will copy memory, and swap the bytes on a big endian machine.
198
 
 * On a little endian machine it is the same as COPY.
199
 
 */
200
 
#define CS_MOVE_DISK_1(d, s)    ((d)[0] = (s)[0])
201
 
#define CS_MOVE_DISK_2(d, s)    do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
202
 
#define CS_MOVE_DISK_3(d, s)    do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
203
 
#define CS_MOVE_DISK_4(d, s)    do { (d)[0] = (s)[3]; (d)[1] = (s)[2]; (d)[2] = (s)[1]; (d)[3] = (s)[0]; } while (0)
204
 
#define CS_MOVE_DISK_8(d, s)    do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; \
205
 
                                                                         (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
206
 
                                                                         (d)[4] = (s)[3]; (d)[5] = (s)[2]; \
207
 
                                                                         (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
208
 
 
209
 
/*
210
 
 * Copy just copies the number of bytes assuming the data is not alligned.
211
 
 */
212
 
#define CS_COPY_DISK_1(d, s)    (d)[0] = s
213
 
#define CS_COPY_DISK_2(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; } while (0)
214
 
#define CS_COPY_DISK_3(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; } while (0)
215
 
#define CS_COPY_DISK_4(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] = (s)[3]; } while (0)
216
 
#define CS_COPY_DISK_6(d, s)    memcpy(&((d)[0]), &((s)[0]), 6)
217
 
#define CS_COPY_DISK_8(d, s)    memcpy(&((d)[0]), &((s)[0]), 8)
218
 
#define CS_COPY_DISK_10(d, s)   memcpy(&((d)[0]), &((s)[0]), 10)
219
 
 
220
 
#define CS_SET_NULL_DISK_1(d)   CS_SET_DISK_1(d, 0)
221
 
#define CS_SET_NULL_DISK_2(d)   do { (d)[0] = 0; (d)[1] = 0; } while (0)
222
 
#define CS_SET_NULL_DISK_4(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; } while (0)
223
 
#define CS_SET_NULL_DISK_6(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; (d)[4] = 0; (d)[5] = 0; } while (0)
224
 
#define CS_SET_NULL_DISK_8(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; (d)[4] = 0; (d)[5] = 0; (d)[6] = 0; (d)[7] = 0; } while (0)
225
 
 
226
 
#define CS_IS_NULL_DISK_1(d)    (!(CS_GET_DISK_1(d)))
227
 
#define CS_IS_NULL_DISK_4(d)    (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3])
228
 
#define CS_IS_NULL_DISK_8(d)    (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3] && !(d)[4] && !(d)[5] && !(d)[6] && !(7)[3])
229
 
 
230
 
#define CS_EQ_DISK_4(d, s)              ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3])
231
 
#define CS_EQ_DISK_8(d, s)              ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3] && \
232
 
                                                                (d)[4] == (s)[4] && (d)[5] == (s)[5] && (d)[6] == (s)[6] && (d)[7] == (s)[7])
233
 
 
234
 
#define CS_IS_FF_DISK_4(d)              ((d)[0] == 0xFF && (d)[1] == 0xFF && (d)[2] == 0xFF && (d)[3] == 0xFF)
235
 
#else
236
 
/*
237
 
 * The native order of the machine is little endian. This means the data to
238
 
 * and from disk need not be swapped. In addition to this, since
239
 
 * the i386 can access non-aligned memory we are not required to
240
 
 * handle the data byte-for-byte.
241
 
 */
242
 
#define CS_SET_DISK_1(d, s)             ((d)[0] = (uint8_t) (s))
243
 
#define CS_SET_DISK_2(d, s)             (*((uint16_t *) &((d)[0])) = (uint16_t) (s))
244
 
#define CS_SET_DISK_3(d, s)             do { (*((uint16_t *) &((d)[0])) = (uint16_t) (s));  *((uint8_t *) &((d)[2])) = (uint8_t) (((uint32_t) (s)) >> 16); } while (0)
245
 
#define CS_SET_DISK_4(d, s)             (*((uint32_t *) &((d)[0])) = (uint32_t) (s))
246
 
#define CS_SET_DISK_6(d, s)             do { *((uint32_t *) &((d)[0])) = (uint32_t) (s); *((uint16_t *) &((d)[4])) = (uint16_t) (((uint64_t) (s)) >> 32); } while (0)
247
 
#define CS_SET_DISK_8(d, s)             (*((uint64_t *) &((d)[0])) = (uint64_t) (s))
248
 
 
249
 
#define CS_GET_DISK_1(s)                ((s)[0])
250
 
#define CS_GET_DISK_2(s)                *((uint16_t *) &((s)[0]))
251
 
#define CS_GET_DISK_3(s)                ((uint32_t) *((uint16_t *) &((s)[0])) | (((uint32_t) *((uint8_t *) &((s)[2]))) << 16))
252
 
#define CS_GET_DISK_4(s)                *((uint32_t *) &((s)[0]))
253
 
#define CS_GET_DISK_6(s)                ((uint64_t) *((uint32_t *) &((s)[0])) | (((uint64_t) *((uint16_t *) &((s)[4]))) << 32))
254
 
#define CS_GET_DISK_8(s)                *((uint64_t *) &((s)[0]))
255
 
 
256
 
#define CS_MOVE_DISK_1(d, s)    ((d)[0] = (s)[0])
257
 
#define CS_MOVE_DISK_2(d, s)    CS_COPY_DISK_2(d, s)
258
 
#define CS_MOVE_DISK_3(d, s)    CS_COPY_DISK_3(d, s)
259
 
#define CS_MOVE_DISK_4(d, s)    CS_COPY_DISK_4(d, s)
260
 
#define CS_MOVE_DISK_8(d, s)    CS_COPY_DISK_8(d, s)
261
 
 
262
 
#define CS_COPY_DISK_1(d, s)    (d)[0] = s
263
 
#define CS_COPY_DISK_2(d, s)    (*((uint16_t *) &((d)[0])) = (*((uint16_t *) &((s)[0]))))
264
 
#define CS_COPY_DISK_3(d, s)    do { *((uint16_t *) &((d)[0])) = *((uint16_t *) &((s)[0])); (d)[2] = (s)[2]; } while (0)
265
 
#define CS_COPY_DISK_4(d, s)    (*((uint32_t *) &((d)[0])) = (*((uint32_t *) &((s)[0]))))
266
 
#define CS_COPY_DISK_6(d, s)    do { *((uint32_t *) &((d)[0])) = *((uint32_t *) &((s)[0])); *((uint16_t *) &((d)[4])) = *((uint16_t *) &((s)[4])); } while (0)
267
 
#define CS_COPY_DISK_8(d, s)    (*((uint64_t *) &(d[0])) = (*((uint64_t *) &((s)[0]))))
268
 
#define CS_COPY_DISK_10(d, s)   memcpy(&((d)[0]), &((s)[0]), 10)
269
 
 
270
 
#define CS_SET_NULL_DISK_1(d)   CS_SET_DISK_1(d, 0)
271
 
#define CS_SET_NULL_DISK_2(d)   CS_SET_DISK_2(d, 0)
272
 
#define CS_SET_NULL_DISK_3(d)   CS_SET_DISK_3(d, 0)
273
 
#define CS_SET_NULL_DISK_4(d)   CS_SET_DISK_4(d, 0L)
274
 
#define CS_SET_NULL_DISK_6(d)   CS_SET_DISK_6(d, 0LL)
275
 
#define CS_SET_NULL_DISK_8(d)   CS_SET_DISK_8(d, 0LL)
276
 
 
277
 
#define CS_IS_NULL_DISK_1(d)    (!(CS_GET_DISK_1(d)))
278
 
#define CS_IS_NULL_DISK_2(d)    (!(CS_GET_DISK_2(d)))
279
 
#define CS_IS_NULL_DISK_3(d)    (!(CS_GET_DISK_3(d)))
280
 
#define CS_IS_NULL_DISK_4(d)    (!(CS_GET_DISK_4(d)))
281
 
#define CS_IS_NULL_DISK_8(d)    (!(CS_GET_DISK_8(d)))
282
 
 
283
 
#define CS_EQ_DISK_4(d, s)              (CS_GET_DISK_4(d) == CS_GET_DISK_4(s))
284
 
#define CS_EQ_DISK_8(d, s)              (CS_GET_DISK_8(d) == CS_GET_DISK_8(s))
285
 
 
286
 
#define CS_IS_FF_DISK_4(d)              (CS_GET_DISK_4(d) == 0xFFFFFFFF)
287
 
#endif
288
 
 
289
 
#define CS_CMP_DISK_4(a, b)             ((int32_t) CS_GET_DISK_4(a) - (int32_t) CS_GET_DISK_4(b))
290
 
#define CS_CMP_DISK_8(d, s)             memcmp(&((d)[0]), &((s)[0]), 8)
291
 
//#define CS_CMP_DISK_8(d, s)           (CS_CMP_DISK_4((d).h_number_4, (s).h_number_4) == 0 ? CS_CMP_DISK_4((d).h_file_4, (s).h_file_4) : CS_CMP_DISK_4((d).h_number_4, (s).h_number_4))
292
 
 
293
 
#define CS_SWAP_DISK_2(d, s)    do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
294
 
#define CS_SWAP_DISK_3(d, s)    do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
295
 
#define CS_SWAP_DISK_4(d, s)    do { (d)[0] = (s)[3]; (d)[1] = (s)[2]; (d)[2] = (s)[1]; (d)[3] = (s)[0]; } while (0)
296
 
#define CS_SWAP_DISK_8(d, s)    do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
297
 
                                                                         (d)[4] = (s)[3]; (d)[5] = (s)[2]; (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
298
 
 
299
 
typedef union {
300
 
        CSDiskValue1 val_1;
301
 
        CSDiskValue4 val_4;
302
 
} CSIntRec, *CSIntPtr;
303
 
 
304
 
typedef union {
305
 
                const char *rec_cchars;
306
 
                char *rec_chars;
307
 
                CSIntPtr int_val;
308
 
} CSDiskData;
309
 
 
310
 
#define CHECKSUM_VALUE_SIZE                     16
311
 
typedef struct {
312
 
        u_char val[CHECKSUM_VALUE_SIZE];
313
 
} Md5Digest;
314
 
 
315
 
        
316
 
#endif