5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/SILC Types
24 * This header includes the most basic types used in the SILC source
25 * tree, such as arithmetic types and their manipulation macros. This
26 * file is included in the silcincludes.h and is automatically available
34 /****d* silcutil/SILCTypes/TRUE
42 * Boolean true value indicator.
51 /****d* silcutil/SILCTypes/FALSE
59 * Boolean false value indicator.
68 /****d* silcutil/SILCTypes/bool
76 * Boolean value, and is 8-bits. Represents value 0 or 1. In
77 * C++ code this type is defined by the C++, and this definition is
84 #define bool unsigned char
89 #define silc_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
91 #if SILC_SIZEOF_SHORT > 2
92 #error "size of the short must be 2 bytes"
95 /****d* silcutil/SILCTypes/SilcUInt8
99 * typedef unsigned char SilcUInt8;
103 * 8-bit unsigned integer.
107 typedef unsigned char SilcUInt8;
110 /****d* silcutil/SILCTypes/SilcInt8
114 * typedef signed char SilcInt8;
118 * 8-bit signed integer.
122 typedef signed char SilcInt8;
125 /****d* silcutil/SILCTypes/SilcUInt16
129 * typedef unsigned short SilcUInt16;
133 * 16-bit unsigned integer. Guaranteed to be 16-bits.
137 typedef unsigned short SilcUInt16;
140 /****d* silcutil/SILCTypes/SilcInt16
144 * typedef signed short SilcInt16;
148 * 16-bit signed integer. Guaranteed to be 16-bits.
152 typedef signed short SilcInt16;
155 /****d* silcutil/SILCTypes/SilcUInt32
159 * typedef unsigned long SilcUInt32;
163 * 32-bit unsigned integer. Guaranteed to be 32-bits.
167 #if SILC_SIZEOF_LONG == 4
168 typedef unsigned long SilcUInt32;
169 typedef signed long SilcInt32;
171 #if SILC_SIZEOF_INT == 4
172 typedef unsigned int SilcUInt32;
173 typedef signed int SilcInt32;
175 #if SILC_SIZEOF_LONG_LONG >= 4
177 typedef unsigned long long SilcUInt32;
178 typedef signed long long SilcInt32;
185 /****d* silcutil/SILCTypes/SilcInt32
189 * typedef signed long SilcInt32;
193 * 32-bit signed integer. Guaranteed to be 32-bits.
197 /****d* silcutil/SILCTypes/SilcUInt64
201 * typedef unsigned long long SilcUInt64;
205 * 64-bit unsigned integer. Guaranteed to be 64-bits on systems that
210 #if SILC_SIZEOF_LONG >= 8
211 typedef unsigned long SilcUInt64;
212 typedef signed long SilcInt64;
214 #if SILC_SIZEOF_LONG_LONG >= 8
216 typedef unsigned long long SilcUInt64;
217 typedef signed long long SilcInt64;
219 typedef SilcUInt32 SilcUInt64; /* XXX Use Windows's own 64 bit types */
220 typedef SilcInt32 SilcInt64;
223 typedef SilcUInt32 SilcUInt64;
224 typedef SilcInt32 SilcInt64;
229 /****d* silcutil/SILCTypes/SilcInt64
233 * typedef signed long long SilcInt64;
237 * 64-bit signed integer. Guaranteed to be 64-bits on systems that
242 #if SILC_SIZEOF_VOID_P < 4
243 typedef SilcUInt32 * void *;
248 #define GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
249 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
250 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
251 | ((SilcUInt32)(SilcUInt8)(cp)[3])
253 /****d* silcutil/SILCTypes/SILC_GET16_MSB
257 * #define SILC_GET16_MSB ...
261 * Return two 8-bit bytes, most significant bytes first.
265 #define SILC_GET16_MSB(l, cp) \
267 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \
268 | ((SilcUInt32)(SilcUInt8)(cp)[1]); \
272 /****d* silcutil/SILCTypes/SILC_GET32_MSB
276 * #define SILC_GET32_MSB ...
280 * Return four 8-bit bytes, most significant bytes first.
284 #define SILC_GET32_MSB(l, cp) \
286 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
287 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
288 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
289 | ((SilcUInt32)(SilcUInt8)(cp)[3]); \
293 /****d* silcutil/SILCTypes/SILC_GET64_MSB
297 * #define SILC_GET64_MSB ...
301 * Return eight 8-bit bytes, most significant bytes first.
305 #define SILC_GET64_MSB(l, cp) \
307 (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) | \
308 ((SilcUInt64)GET_WORD((cp) + 4))); \
312 /****d* silcutil/SILCTypes/SILC_GET16_LSB
316 * #define SILC_GET16_MSB ...
320 * Return two 8-bit bytes, least significant bytes first.
324 #define SILC_GET16_LSB(l, cp) \
326 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
327 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8); \
331 /****d* silcutil/SILCTypes/SILC_GET32_LSB
335 * #define SILC_GET32_LSB ...
339 * Return four 8-bit bytes, least significant bytes first.
343 #define SILC_GET32_LSB(l, cp) \
345 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
346 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
347 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
348 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24); \
351 /* Same as upper but XOR the result always. Special purpose macro. */
352 #define SILC_GET32_X_LSB(l, cp) \
353 (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \
354 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
355 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
356 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
359 /****d* silcutil/SILCTypes/SILC_PUT16_MSB
363 * #define SILC_PUT16_MSB ...
367 * Put two 8-bit bytes, most significant bytes first.
371 #define SILC_PUT16_MSB(l, cp) \
373 (cp)[0] = (SilcUInt8)((l) >> 8); \
374 (cp)[1] = (SilcUInt8)(l); \
378 /****d* silcutil/SILCTypes/SILC_PUT32_MSB
382 * #define SILC_PUT32_MSB ...
386 * Put four 8-bit bytes, most significant bytes first.
390 #define SILC_PUT32_MSB(l, cp) \
392 (cp)[0] = (SilcUInt8)((l) >> 24); \
393 (cp)[1] = (SilcUInt8)((l) >> 16); \
394 (cp)[2] = (SilcUInt8)((l) >> 8); \
395 (cp)[3] = (SilcUInt8)(l); \
399 /****d* silcutil/SILCTypes/SILC_PUT64_MSB
403 * #define SILC_PUT64_MSB ...
407 * Put eight 8-bit bytes, most significant bytes first.
411 #define SILC_PUT64_MSB(l, cp) \
413 SILC_PUT32_MSB((SilcUInt32)((SilcUInt64)(l) >> 32), (cp)); \
414 SILC_PUT32_MSB((SilcUInt32)(l), (cp) + 4); \
418 /****d* silcutil/SILCTypes/SILC_PUT16_LSB
422 * #define SILC_PUT16_LSB ...
426 * Put two 8-bit bytes, least significant bytes first.
430 #define SILC_PUT16_LSB(l, cp) \
432 (cp)[0] = (SilcUInt8)(l); \
433 (cp)[1] = (SilcUInt8)((l) >> 8); \
437 /****d* silcutil/SILCTypes/SILC_PUT32_LSB
441 * #define SILC_PUT32_LSB ...
445 * Put four 8-bit bytes, least significant bytes first.
449 #define SILC_PUT32_LSB(l, cp) \
451 (cp)[0] = (SilcUInt8)(l); \
452 (cp)[1] = (SilcUInt8)((l) >> 8); \
453 (cp)[2] = (SilcUInt8)((l) >> 16); \
454 (cp)[3] = (SilcUInt8)((l) >> 24); \
458 #endif /* SILCTYPES_H */