00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #pragma once
00031 #ifndef __CSDEFS_H__
00032 #define __CSDEFS_H__
00033
00034 #include <sys/types.h>
00035
00036
00037 #include <stdint.h>
00038
00039
00040
00041
00042
00043 #ifdef OS_WINDOWS
00044 #define __FUNC__ __FUNCTION__
00045 #elif defined(OS_SOLARIS)
00046 #define __FUNC__ "__func__"
00047 #else
00048 #define __FUNC__ __PRETTY_FUNCTION__
00049 #endif
00050
00051
00052
00053
00054 #ifndef u_char
00055 #define u_char unsigned char
00056 #endif
00057
00058
00059
00060
00061 #define s_char unsigned char
00062
00063
00064 #define off64_t uint64_t
00065
00066
00067
00068
00069
00070
00071
00072 #define s_int int_fast32_t
00073
00074
00075 class CSThread;
00076
00077
00078 #define UNUSED(x) (void)x
00079
00080 #ifdef OS_WINDOWS
00081
00082 #define CS_DEFAULT_EOL "\r\n"
00083 #define CS_DIR_CHAR '\\'
00084 #define CS_DIR_DELIM "\\"
00085 #define IS_DIR_CHAR(ch) ((ch) == CS_DIR_CHAR || (ch) == '/')
00086
00087 #ifndef PATH_MAX
00088 #define PATH_MAX MAX_PATH
00089 #endif
00090
00091 #ifndef NAME_MAX
00092 #define NAME_MAX MAX_PATH
00093 #endif
00094
00095 #else
00096
00097 #define CS_DEFAULT_EOL "\n"
00098 #define CS_DIR_CHAR '/'
00099 #define CS_DIR_DELIM "/"
00100 #define IS_DIR_CHAR(ch) ((ch) == CS_DIR_CHAR)
00101
00102 #endif // OS_WINDOWS
00103
00104 #define CS_CALL_STACK_SIZE 100
00105 #define CS_RELEASE_STACK_SIZE 200
00106 #define CS_JUMP_STACK_SIZE 20 // NOTE: If a stack overflow occurs check that there are no returns inside of try_() blocks.
00107
00108
00109 #define CS_WIDTH_INT_8 5
00110 #define CS_WIDTH_INT_16 7
00111 #define CS_WIDTH_INT_32 12
00112 #define CS_WIDTH_INT_64 22
00113
00114 typedef uint8_t CSDiskValue1[1];
00115 typedef uint8_t CSDiskValue2[2];
00116 typedef uint8_t CSDiskValue3[3];
00117 typedef uint8_t CSDiskValue4[4];
00118 typedef uint8_t CSDiskValue6[6];
00119 typedef uint8_t CSDiskValue8[8];
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 #if BYTE_ORDER == BIG_ENDIAN
00156
00157
00158
00159
00160 #define CS_SET_DISK_1(d, s) ((d)[0] = (uint8_t) (s))
00161
00162 #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)
00163
00164 #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); \
00165 (d)[2] = (uint8_t) ((((uint32_t) (s)) >> 16) & 0xFF); } while (0)
00166
00167 #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); \
00168 (d)[2] = (uint8_t) ((((uint32_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint32_t) (s)) >> 24) & 0xFF); } while (0)
00169
00170 #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); \
00171 (d)[2] = (uint8_t) ((((uint64_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint64_t) (s)) >> 24) & 0xFF); \
00172 (d)[4] = (uint8_t) ((((uint64_t) (s)) >> 32) & 0xFF); (d)[5] = (uint8_t) ((((uint64_t) (s)) >> 40) & 0xFF); } while (0)
00173
00174 #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); \
00175 (d)[2] = (uint8_t) ((((uint64_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint64_t) (s)) >> 24) & 0xFF); \
00176 (d)[4] = (uint8_t) ((((uint64_t) (s)) >> 32) & 0xFF); (d)[5] = (uint8_t) ((((uint64_t) (s)) >> 40) & 0xFF); \
00177 (d)[6] = (uint8_t) ((((uint64_t) (s)) >> 48) & 0xFF); (d)[7] = (uint8_t) ((((uint64_t) (s)) >> 56) & 0xFF); } while (0)
00178
00179 #define CS_GET_DISK_1(s) ((s)[0])
00180
00181 #define CS_GET_DISK_2(s) ((uint16_t) (((uint16_t) (s)[0]) | (((uint16_t) (s)[1]) << 8)))
00182
00183 #define CS_GET_DISK_3(s) ((uint32_t) (((uint32_t) (s)[0]) | (((uint32_t) (s)[1]) << 8) | (((uint32_t) (s)[2]) << 16)))
00184
00185 #define CS_GET_DISK_4(s) (((uint32_t) (s)[0]) | (((uint32_t) (s)[1]) << 8 ) | \
00186 (((uint32_t) (s)[2]) << 16) | (((uint32_t) (s)[3]) << 24))
00187
00188 #define CS_GET_DISK_6(s) (((uint64_t) (s)[0]) | (((uint64_t) (s)[1]) << 8 ) | \
00189 (((uint64_t) (s)[2]) << 16) | (((uint64_t) (s)[3]) << 24) | \
00190 (((uint64_t) (s)[4]) << 32) | (((uint64_t) (s)[5]) << 40))
00191
00192 #define CS_GET_DISK_8(s) (((uint64_t) (s)[0]) | (((uint64_t) (s)[1]) << 8 ) | \
00193 (((uint64_t) (s)[2]) << 16) | (((uint64_t) (s)[3]) << 24) | \
00194 (((uint64_t) (s)[4]) << 32) | (((uint64_t) (s)[5]) << 40) | \
00195 (((uint64_t) (s)[6]) << 48) | (((uint64_t) (s)[7]) << 56))
00196
00197
00198
00199
00200 #define CS_MOVE_DISK_1(d, s) ((d)[0] = (s)[0])
00201 #define CS_MOVE_DISK_2(d, s) do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
00202 #define CS_MOVE_DISK_3(d, s) do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
00203 #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)
00204 #define CS_MOVE_DISK_8(d, s) do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; \
00205 (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
00206 (d)[4] = (s)[3]; (d)[5] = (s)[2]; \
00207 (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
00208
00209
00210
00211
00212 #define CS_COPY_DISK_1(d, s) (d)[0] = s
00213 #define CS_COPY_DISK_2(d, s) do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; } while (0)
00214 #define CS_COPY_DISK_3(d, s) do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; } while (0)
00215 #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)
00216 #define CS_COPY_DISK_6(d, s) memcpy(&((d)[0]), &((s)[0]), 6)
00217 #define CS_COPY_DISK_8(d, s) memcpy(&((d)[0]), &((s)[0]), 8)
00218 #define CS_COPY_DISK_10(d, s) memcpy(&((d)[0]), &((s)[0]), 10)
00219
00220 #define CS_SET_NULL_DISK_1(d) CS_SET_DISK_1(d, 0)
00221 #define CS_SET_NULL_DISK_2(d) do { (d)[0] = 0; (d)[1] = 0; } while (0)
00222 #define CS_SET_NULL_DISK_4(d) do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; } while (0)
00223 #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)
00224 #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)
00225
00226 #define CS_IS_NULL_DISK_1(d) (!(CS_GET_DISK_1(d)))
00227 #define CS_IS_NULL_DISK_4(d) (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3])
00228 #define CS_IS_NULL_DISK_8(d) (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3] && !(d)[4] && !(d)[5] && !(d)[6] && !(7)[3])
00229
00230 #define CS_EQ_DISK_4(d, s) ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3])
00231 #define CS_EQ_DISK_8(d, s) ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3] && \
00232 (d)[4] == (s)[4] && (d)[5] == (s)[5] && (d)[6] == (s)[6] && (d)[7] == (s)[7])
00233
00234 #define CS_IS_FF_DISK_4(d) ((d)[0] == 0xFF && (d)[1] == 0xFF && (d)[2] == 0xFF && (d)[3] == 0xFF)
00235 #else
00236
00237
00238
00239
00240
00241
00242 #define CS_SET_DISK_1(d, s) ((d)[0] = (uint8_t) (s))
00243 #define CS_SET_DISK_2(d, s) (*((uint16_t *) &((d)[0])) = (uint16_t) (s))
00244 #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)
00245 #define CS_SET_DISK_4(d, s) (*((uint32_t *) &((d)[0])) = (uint32_t) (s))
00246 #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)
00247 #define CS_SET_DISK_8(d, s) (*((uint64_t *) &((d)[0])) = (uint64_t) (s))
00248
00249 #define CS_GET_DISK_1(s) ((s)[0])
00250 #define CS_GET_DISK_2(s) *((uint16_t *) &((s)[0]))
00251 #define CS_GET_DISK_3(s) ((uint32_t) *((uint16_t *) &((s)[0])) | (((uint32_t) *((uint8_t *) &((s)[2]))) << 16))
00252 #define CS_GET_DISK_4(s) *((uint32_t *) &((s)[0]))
00253 #define CS_GET_DISK_6(s) ((uint64_t) *((uint32_t *) &((s)[0])) | (((uint64_t) *((uint16_t *) &((s)[4]))) << 32))
00254 #define CS_GET_DISK_8(s) *((uint64_t *) &((s)[0]))
00255
00256 #define CS_MOVE_DISK_1(d, s) ((d)[0] = (s)[0])
00257 #define CS_MOVE_DISK_2(d, s) CS_COPY_DISK_2(d, s)
00258 #define CS_MOVE_DISK_3(d, s) CS_COPY_DISK_3(d, s)
00259 #define CS_MOVE_DISK_4(d, s) CS_COPY_DISK_4(d, s)
00260 #define CS_MOVE_DISK_8(d, s) CS_COPY_DISK_8(d, s)
00261
00262 #define CS_COPY_DISK_1(d, s) (d)[0] = s
00263 #define CS_COPY_DISK_2(d, s) (*((uint16_t *) &((d)[0])) = (*((uint16_t *) &((s)[0]))))
00264 #define CS_COPY_DISK_3(d, s) do { *((uint16_t *) &((d)[0])) = *((uint16_t *) &((s)[0])); (d)[2] = (s)[2]; } while (0)
00265 #define CS_COPY_DISK_4(d, s) (*((uint32_t *) &((d)[0])) = (*((uint32_t *) &((s)[0]))))
00266 #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)
00267 #define CS_COPY_DISK_8(d, s) (*((uint64_t *) &(d[0])) = (*((uint64_t *) &((s)[0]))))
00268 #define CS_COPY_DISK_10(d, s) memcpy(&((d)[0]), &((s)[0]), 10)
00269
00270 #define CS_SET_NULL_DISK_1(d) CS_SET_DISK_1(d, 0)
00271 #define CS_SET_NULL_DISK_2(d) CS_SET_DISK_2(d, 0)
00272 #define CS_SET_NULL_DISK_3(d) CS_SET_DISK_3(d, 0)
00273 #define CS_SET_NULL_DISK_4(d) CS_SET_DISK_4(d, 0L)
00274 #define CS_SET_NULL_DISK_6(d) CS_SET_DISK_6(d, 0LL)
00275 #define CS_SET_NULL_DISK_8(d) CS_SET_DISK_8(d, 0LL)
00276
00277 #define CS_IS_NULL_DISK_1(d) (!(CS_GET_DISK_1(d)))
00278 #define CS_IS_NULL_DISK_2(d) (!(CS_GET_DISK_2(d)))
00279 #define CS_IS_NULL_DISK_3(d) (!(CS_GET_DISK_3(d)))
00280 #define CS_IS_NULL_DISK_4(d) (!(CS_GET_DISK_4(d)))
00281 #define CS_IS_NULL_DISK_8(d) (!(CS_GET_DISK_8(d)))
00282
00283 #define CS_EQ_DISK_4(d, s) (CS_GET_DISK_4(d) == CS_GET_DISK_4(s))
00284 #define CS_EQ_DISK_8(d, s) (CS_GET_DISK_8(d) == CS_GET_DISK_8(s))
00285
00286 #define CS_IS_FF_DISK_4(d) (CS_GET_DISK_4(d) == 0xFFFFFFFF)
00287 #endif
00288
00289 #define CS_CMP_DISK_4(a, b) ((int32_t) CS_GET_DISK_4(a) - (int32_t) CS_GET_DISK_4(b))
00290 #define CS_CMP_DISK_8(d, s) memcmp(&((d)[0]), &((s)[0]), 8)
00291
00292
00293 #define CS_SWAP_DISK_2(d, s) do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
00294 #define CS_SWAP_DISK_3(d, s) do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
00295 #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)
00296 #define CS_SWAP_DISK_8(d, s) do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
00297 (d)[4] = (s)[3]; (d)[5] = (s)[2]; (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
00298
00299 typedef union {
00300 CSDiskValue1 val_1;
00301 CSDiskValue4 val_4;
00302 } CSIntRec, *CSIntPtr;
00303
00304 typedef union {
00305 const char *rec_cchars;
00306 char *rec_chars;
00307 CSIntPtr int_val;
00308 } CSDiskData;
00309
00310 #define CHECKSUM_VALUE_SIZE 16
00311 typedef struct {
00312 u_char val[CHECKSUM_VALUE_SIZE];
00313 } Md5Digest;
00314
00315
00316 #endif