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
43 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
46 #if SILC_SIZEOF_SHORT > 2
47 #error "size of the short must be 2 bytes"
50 /****d* silcutil/SILCTypes/SilcUInt8
54 * typedef unsigned char SilcUInt8;
58 * 8-bit unsigned integer.
62 typedef unsigned char SilcUInt8;
65 /****d* silcutil/SILCTypes/SilcInt8
69 * typedef signed char SilcInt8;
73 * 8-bit signed integer.
77 typedef signed char SilcInt8;
80 /****d* silcutil/SILCTypes/SilcUInt16
84 * typedef unsigned short SilcUInt16;
88 * 16-bit unsigned integer. Guaranteed to be 16-bits.
92 typedef unsigned short SilcUInt16;
95 /****d* silcutil/SILCTypes/SilcInt16
99 * typedef signed short SilcInt16;
103 * 16-bit signed integer. Guaranteed to be 16-bits.
107 typedef signed short SilcInt16;
110 /****d* silcutil/SILCTypes/SilcUInt32
114 * typedef unsigned long SilcUInt32;
118 * 32-bit unsigned integer. Guaranteed to be 32-bits.
122 #if SILC_SIZEOF_LONG == 4
123 typedef unsigned long SilcUInt32;
124 typedef signed long SilcInt32;
126 #if SILC_SIZEOF_INT == 4
127 typedef unsigned int SilcUInt32;
128 typedef signed int SilcInt32;
130 #if SILC_SIZEOF_LONG_LONG >= 4
132 typedef unsigned long long SilcUInt32;
133 typedef signed long long SilcInt32;
140 /****d* silcutil/SILCTypes/SilcInt32
144 * typedef signed long SilcInt32;
148 * 32-bit signed integer. Guaranteed to be 32-bits.
152 /****d* silcutil/SILCTypes/SilcUInt64
156 * typedef unsigned long long SilcUInt64;
160 * 64-bit unsigned integer. Guaranteed to be 64-bits on systems that
165 #if SILC_SIZEOF_LONG >= 8
166 typedef unsigned long SilcUInt64;
167 typedef signed long SilcInt64;
169 #if SILC_SIZEOF_LONG_LONG >= 8
171 typedef unsigned long long SilcUInt64;
172 typedef signed long long SilcInt64;
174 typedef SilcUInt32 SilcUInt64; /* XXX Use Windows's own 64 bit types */
175 typedef SilcInt32 SilcInt64;
178 typedef SilcUInt32 SilcUInt64;
179 typedef SilcInt32 SilcInt64;
184 /****d* silcutil/SILCTypes/SilcInt64
188 * typedef signed long long SilcInt64;
192 * 64-bit signed integer. Guaranteed to be 64-bits on systems that
197 #if SILC_SIZEOF_VOID_P < 4
198 typedef SilcUInt32 * void *;
203 #define bool unsigned char
207 #define GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
208 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
209 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
210 | ((SilcUInt32)(SilcUInt8)(cp)[3])
212 /****d* silcutil/SILCTypes/SILC_GET16_MSB
216 * #define SILC_GET16_MSB ...
220 * Return two 8-bit bytes, most significant bytes first.
224 #define SILC_GET16_MSB(l, cp) \
225 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \
226 | ((SilcUInt32)(SilcUInt8)(cp)[1])
229 /****d* silcutil/SILCTypes/SILC_GET32_MSB
233 * #define SILC_GET32_MSB ...
237 * Return four 8-bit bytes, most significant bytes first.
241 #define SILC_GET32_MSB(l, cp) \
242 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
243 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
244 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
245 | ((SilcUInt32)(SilcUInt8)(cp)[3])
248 /****d* silcutil/SILCTypes/SILC_GET64_MSB
252 * #define SILC_GET64_MSB ...
256 * Return eight 8-bit bytes, most significant bytes first.
260 #define SILC_GET64_MSB(l, cp) \
261 (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) | \
262 ((SilcUInt64)GET_WORD((cp) + 4)))
265 /****d* silcutil/SILCTypes/SILC_GET16_LSB
269 * #define SILC_GET16_MSB ...
273 * Return two 8-bit bytes, least significant bytes first.
277 #define SILC_GET16_LSB(l, cp) \
278 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
279 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8)
282 /****d* silcutil/SILCTypes/SILC_GET32_LSB
286 * #define SILC_GET32_LSB ...
290 * Return four 8-bit bytes, least significant bytes first.
294 #define SILC_GET32_LSB(l, cp) \
295 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
296 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
297 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
298 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
300 /* Same as upper but XOR the result always. Special purpose macro. */
301 #define SILC_GET32_X_LSB(l, cp) \
302 (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \
303 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
304 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
305 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
308 /****d* silcutil/SILCTypes/SILC_PUT16_MSB
312 * #define SILC_PUT16_MSB ...
316 * Put two 8-bit bytes, most significant bytes first.
320 #define SILC_PUT16_MSB(l, cp) \
325 /****d* silcutil/SILCTypes/SILC_PUT32_MSB
329 * #define SILC_PUT32_MSB ...
333 * Put four 8-bit bytes, most significant bytes first.
337 #define SILC_PUT32_MSB(l, cp) \
344 /****d* silcutil/SILCTypes/SILC_PUT64_MSB
348 * #define SILC_PUT64_MSB ...
352 * Put eight 8-bit bytes, most significant bytes first.
356 #define SILC_PUT64_MSB(l, cp) \
358 SILC_PUT32_MSB((SilcUInt32)((SilcUInt64)(l) >> 32), (cp)); \
359 SILC_PUT32_MSB((SilcUInt32)(l), (cp) + 4); \
363 /****d* silcutil/SILCTypes/SILC_PUT16_LSB
367 * #define SILC_PUT16_LSB ...
371 * Put two 8-bit bytes, least significant bytes first.
375 #define SILC_PUT16_LSB(l, cp) \
380 /****d* silcutil/SILCTypes/SILC_PUT32_LSB
384 * #define SILC_PUT32_LSB ...
388 * Put four 8-bit bytes, least significant bytes first.
392 #define SILC_PUT32_LSB(l, cp) \
399 #endif /* SILCTYPES_H */