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) \
266 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \
267 | ((SilcUInt32)(SilcUInt8)(cp)[1])
270 /****d* silcutil/SILCTypes/SILC_GET32_MSB
274 * #define SILC_GET32_MSB ...
278 * Return four 8-bit bytes, most significant bytes first.
282 #define SILC_GET32_MSB(l, cp) \
283 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
284 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
285 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
286 | ((SilcUInt32)(SilcUInt8)(cp)[3])
289 /****d* silcutil/SILCTypes/SILC_GET64_MSB
293 * #define SILC_GET64_MSB ...
297 * Return eight 8-bit bytes, most significant bytes first.
301 #define SILC_GET64_MSB(l, cp) \
302 (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) | \
303 ((SilcUInt64)GET_WORD((cp) + 4)))
306 /****d* silcutil/SILCTypes/SILC_GET16_LSB
310 * #define SILC_GET16_MSB ...
314 * Return two 8-bit bytes, least significant bytes first.
318 #define SILC_GET16_LSB(l, cp) \
319 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
320 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8)
323 /****d* silcutil/SILCTypes/SILC_GET32_LSB
327 * #define SILC_GET32_LSB ...
331 * Return four 8-bit bytes, least significant bytes first.
335 #define SILC_GET32_LSB(l, cp) \
336 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
337 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
338 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
339 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
341 /* Same as upper but XOR the result always. Special purpose macro. */
342 #define SILC_GET32_X_LSB(l, cp) \
343 (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \
344 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
345 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
346 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
349 /****d* silcutil/SILCTypes/SILC_PUT16_MSB
353 * #define SILC_PUT16_MSB ...
357 * Put two 8-bit bytes, most significant bytes first.
361 #define SILC_PUT16_MSB(l, cp) \
366 /****d* silcutil/SILCTypes/SILC_PUT32_MSB
370 * #define SILC_PUT32_MSB ...
374 * Put four 8-bit bytes, most significant bytes first.
378 #define SILC_PUT32_MSB(l, cp) \
385 /****d* silcutil/SILCTypes/SILC_PUT64_MSB
389 * #define SILC_PUT64_MSB ...
393 * Put eight 8-bit bytes, most significant bytes first.
397 #define SILC_PUT64_MSB(l, cp) \
399 SILC_PUT32_MSB((SilcUInt32)((SilcUInt64)(l) >> 32), (cp)); \
400 SILC_PUT32_MSB((SilcUInt32)(l), (cp) + 4); \
404 /****d* silcutil/SILCTypes/SILC_PUT16_LSB
408 * #define SILC_PUT16_LSB ...
412 * Put two 8-bit bytes, least significant bytes first.
416 #define SILC_PUT16_LSB(l, cp) \
421 /****d* silcutil/SILCTypes/SILC_PUT32_LSB
425 * #define SILC_PUT32_LSB ...
429 * Put four 8-bit bytes, least significant bytes first.
433 #define SILC_PUT32_LSB(l, cp) \
440 #endif /* SILCTYPES_H */