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
91 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
94 #if SILC_SIZEOF_SHORT > 2
95 #error "size of the short must be 2 bytes"
98 /****d* silcutil/SILCTypes/SilcUInt8
102 * typedef unsigned char SilcUInt8;
106 * 8-bit unsigned integer.
110 typedef unsigned char SilcUInt8;
113 /****d* silcutil/SILCTypes/SilcInt8
117 * typedef signed char SilcInt8;
121 * 8-bit signed integer.
125 typedef signed char SilcInt8;
128 /****d* silcutil/SILCTypes/SilcUInt16
132 * typedef unsigned short SilcUInt16;
136 * 16-bit unsigned integer. Guaranteed to be 16-bits.
140 typedef unsigned short SilcUInt16;
143 /****d* silcutil/SILCTypes/SilcInt16
147 * typedef signed short SilcInt16;
151 * 16-bit signed integer. Guaranteed to be 16-bits.
155 typedef signed short SilcInt16;
158 /****d* silcutil/SILCTypes/SilcUInt32
162 * typedef unsigned long SilcUInt32;
166 * 32-bit unsigned integer. Guaranteed to be 32-bits.
170 #if SILC_SIZEOF_LONG == 4
171 typedef unsigned long SilcUInt32;
172 typedef signed long SilcInt32;
174 #if SILC_SIZEOF_INT == 4
175 typedef unsigned int SilcUInt32;
176 typedef signed int SilcInt32;
178 #if SILC_SIZEOF_LONG_LONG >= 4
180 typedef unsigned long long SilcUInt32;
181 typedef signed long long SilcInt32;
188 /****d* silcutil/SILCTypes/SilcInt32
192 * typedef signed long SilcInt32;
196 * 32-bit signed integer. Guaranteed to be 32-bits.
200 /****d* silcutil/SILCTypes/SilcUInt64
204 * typedef unsigned long long SilcUInt64;
208 * 64-bit unsigned integer. Guaranteed to be 64-bits on systems that
213 #if SILC_SIZEOF_LONG >= 8
214 typedef unsigned long SilcUInt64;
215 typedef signed long SilcInt64;
217 #if SILC_SIZEOF_LONG_LONG >= 8
219 typedef unsigned long long SilcUInt64;
220 typedef signed long long SilcInt64;
222 typedef SilcUInt32 SilcUInt64; /* XXX Use Windows's own 64 bit types */
223 typedef SilcInt32 SilcInt64;
226 typedef SilcUInt32 SilcUInt64;
227 typedef SilcInt32 SilcInt64;
232 /****d* silcutil/SILCTypes/SilcInt64
236 * typedef signed long long SilcInt64;
240 * 64-bit signed integer. Guaranteed to be 64-bits on systems that
245 #if SILC_SIZEOF_VOID_P < 4
246 typedef SilcUInt32 * void *;
251 #define GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
252 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
253 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
254 | ((SilcUInt32)(SilcUInt8)(cp)[3])
256 /****d* silcutil/SILCTypes/SILC_GET16_MSB
260 * #define SILC_GET16_MSB ...
264 * Return two 8-bit bytes, most significant bytes first.
268 #define SILC_GET16_MSB(l, cp) \
269 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \
270 | ((SilcUInt32)(SilcUInt8)(cp)[1])
273 /****d* silcutil/SILCTypes/SILC_GET32_MSB
277 * #define SILC_GET32_MSB ...
281 * Return four 8-bit bytes, most significant bytes first.
285 #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])
292 /****d* silcutil/SILCTypes/SILC_GET64_MSB
296 * #define SILC_GET64_MSB ...
300 * Return eight 8-bit bytes, most significant bytes first.
304 #define SILC_GET64_MSB(l, cp) \
305 (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) | \
306 ((SilcUInt64)GET_WORD((cp) + 4)))
309 /****d* silcutil/SILCTypes/SILC_GET16_LSB
313 * #define SILC_GET16_MSB ...
317 * Return two 8-bit bytes, least significant bytes first.
321 #define SILC_GET16_LSB(l, cp) \
322 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
323 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8)
326 /****d* silcutil/SILCTypes/SILC_GET32_LSB
330 * #define SILC_GET32_LSB ...
334 * Return four 8-bit bytes, least significant bytes first.
338 #define SILC_GET32_LSB(l, cp) \
339 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
340 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
341 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
342 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
344 /* Same as upper but XOR the result always. Special purpose macro. */
345 #define SILC_GET32_X_LSB(l, cp) \
346 (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \
347 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
348 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
349 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
352 /****d* silcutil/SILCTypes/SILC_PUT16_MSB
356 * #define SILC_PUT16_MSB ...
360 * Put two 8-bit bytes, most significant bytes first.
364 #define SILC_PUT16_MSB(l, cp) \
369 /****d* silcutil/SILCTypes/SILC_PUT32_MSB
373 * #define SILC_PUT32_MSB ...
377 * Put four 8-bit bytes, most significant bytes first.
381 #define SILC_PUT32_MSB(l, cp) \
388 /****d* silcutil/SILCTypes/SILC_PUT64_MSB
392 * #define SILC_PUT64_MSB ...
396 * Put eight 8-bit bytes, most significant bytes first.
400 #define SILC_PUT64_MSB(l, cp) \
402 SILC_PUT32_MSB((SilcUInt32)((SilcUInt64)(l) >> 32), (cp)); \
403 SILC_PUT32_MSB((SilcUInt32)(l), (cp) + 4); \
407 /****d* silcutil/SILCTypes/SILC_PUT16_LSB
411 * #define SILC_PUT16_LSB ...
415 * Put two 8-bit bytes, least significant bytes first.
419 #define SILC_PUT16_LSB(l, cp) \
424 /****d* silcutil/SILCTypes/SILC_PUT32_LSB
428 * #define SILC_PUT32_LSB ...
432 * Put four 8-bit bytes, least significant bytes first.
436 #define SILC_PUT32_LSB(l, cp) \
443 #endif /* SILCTYPES_H */