X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilctypes.h;h=e98bc8c82bdf47f18a85b4f0a4f7a1d0a9df2897;hb=c257b555225193e54d85daf541d29578b3c93882;hp=5577ae4208d62e1889a8f897e64a302fa78dee4e;hpb=eccd01a53afd8273e9c2ea7ec4238ea2b9f884b0;p=silc.git diff --git a/lib/silcutil/silctypes.h b/lib/silcutil/silctypes.h index 5577ae42..e98bc8c8 100644 --- a/lib/silcutil/silctypes.h +++ b/lib/silcutil/silctypes.h @@ -1,10 +1,10 @@ /* - silctypes.h + silctypes.h Author: Pekka Riikonen - Copyright (C) 2002 Pekka Riikonen + Copyright (C) 2002 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -79,6 +79,10 @@ * * SOURCE */ +#ifdef SILC_MACOSX +#define bool _Bool +#endif + #ifndef __cplusplus #ifndef bool #define bool unsigned char @@ -216,8 +220,8 @@ typedef signed long SilcInt64; typedef unsigned long long SilcUInt64; typedef signed long long SilcInt64; #else -typedef SilcUInt32 SilcUInt64; /* XXX Use Windows's own 64 bit types */ -typedef SilcInt32 SilcInt64; +typedef unsigned __int64 SilcUInt64; +typedef signed __int64 SilcInt64; #endif #else typedef SilcUInt32 SilcUInt64; @@ -245,9 +249,9 @@ typedef SilcUInt32 * void *; /* Macros */ -#define GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \ - | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \ - | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \ +#define SILC_GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \ + | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \ + | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \ | ((SilcUInt32)(SilcUInt8)(cp)[3]) /****d* silcutil/SILCTypes/SILC_GET16_MSB @@ -302,10 +306,10 @@ do { \ * * SOURCE */ -#define SILC_GET64_MSB(l, cp) \ -do { \ - (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) | \ - ((SilcUInt64)GET_WORD((cp) + 4))); \ +#define SILC_GET64_MSB(l, cp) \ +do { \ + (l) = ((((SilcUInt64)SILC_GET_WORD((cp))) << 32) | \ + ((SilcUInt64)SILC_GET_WORD((cp) + 4))); \ } while(0) /***/ @@ -370,8 +374,8 @@ do { \ */ #define SILC_PUT16_MSB(l, cp) \ do { \ - (cp)[0] = l >> 8; \ - (cp)[1] = l; \ + (cp)[0] = (SilcUInt8)((l) >> 8); \ + (cp)[1] = (SilcUInt8)(l); \ } while(0) /***/ @@ -389,10 +393,10 @@ do { \ */ #define SILC_PUT32_MSB(l, cp) \ do { \ - (cp)[0] = l >> 24; \ - (cp)[1] = l >> 16; \ - (cp)[2] = l >> 8; \ - (cp)[3] = l; \ + (cp)[0] = (SilcUInt8)((l) >> 24); \ + (cp)[1] = (SilcUInt8)((l) >> 16); \ + (cp)[2] = (SilcUInt8)((l) >> 8); \ + (cp)[3] = (SilcUInt8)(l); \ } while(0) /***/ @@ -429,8 +433,8 @@ do { \ */ #define SILC_PUT16_LSB(l, cp) \ do { \ - (cp)[0] = l; \ - (cp)[1] = l >> 8; \ + (cp)[0] = (SilcUInt8)(l); \ + (cp)[1] = (SilcUInt8)((l) >> 8); \ } while(0) /***/ @@ -448,11 +452,134 @@ do { \ */ #define SILC_PUT32_LSB(l, cp) \ do { \ - (cp)[0] = l; \ - (cp)[1] = l >> 8; \ - (cp)[2] = l >> 16; \ - (cp)[3] = l >> 24; \ + (cp)[0] = (SilcUInt8)(l); \ + (cp)[1] = (SilcUInt8)((l) >> 8); \ + (cp)[2] = (SilcUInt8)((l) >> 16); \ + (cp)[3] = (SilcUInt8)((l) >> 24); \ } while(0) /***/ +/****d* silcutil/SILCTypes/SILC_SWAB_16 + * + * NAME + * + * #define SILC_SWAB_16 ... + * + * DESCRIPTION + * + * Swabs 16-bit unsigned integer byte order. + * + * SOURCE + */ +#define SILC_SWAB_16(l) \ + ((SilcUInt16)(((SilcUInt16)(l) & (SilcUInt16)0x00FFU) << 8) | \ + (((SilcUInt16)(l) & (SilcUInt16)0xFF00U) >> 8)) +/***/ + +/****d* silcutil/SILCTypes/SILC_SWAB_32 + * + * NAME + * + * #define SILC_SWAB_32 ... + * + * DESCRIPTION + * + * Swabs 32-bit unsigned integer byte order. + * + * SOURCE + */ +#define SILC_SWAB_32(l) \ + ((SilcUInt32)(((SilcUInt32)(l) & (SilcUInt32)0x000000FFUL) << 24) | \ + (((SilcUInt32)(l) & (SilcUInt32)0x0000FF00UL) << 8) | \ + (((SilcUInt32)(l) & (SilcUInt32)0x00FF0000UL) >> 8) | \ + (((SilcUInt32)(l) & (SilcUInt32)0xFF000000UL) >> 24)) +/***/ + +/****d* silcutil/SILCTypes/SILC_PTR_TO_32 + * + * NAME + * + * #define SILC_PTR_TO_32 ... + * + * DESCRIPTION + * + * Type casts a pointer's value into a 32-bit integer. Use this to + * avoid compiler warnings when type casting pointers to integers + * of different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_PTR_TO_32(_ptr__) ((SilcUInt32)(_ptr__)) +#else +#define SILC_PTR_TO_32(_ptr__) \ + ((SilcUInt32)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL)) +#endif +/***/ + +/****d* silcutil/SILCTypes/SILC_PTR_TO_64 + * + * NAME + * + * #define SILC_PTR_TO_64 ... + * + * DESCRIPTION + * + * Type casts a pointer's value into a 64-bit integer. Use this to + * avoid compiler warnings when type casting pointers to integers + * of different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_PTR_TO_64(_ptr__) ((SilcUInt64)((SilcUInt32)(_ptr__))) +#else +#define SILC_PTR_TO_64(_ptr__) \ + ((SilcUInt64)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL)) +#endif +/***/ + +/****d* silcutil/SILCTypes/SILC_32_TO_PTR + * + * NAME + * + * #define SILC_PTR_TO_32 ... + * + * DESCRIPTION + * + * Type casts a 32-bit integer value into a pointer. Use this to + * avoid compiler warnings when type casting integers to pointers of + * different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_32_TO_PTR(_ival__) ((void *)((SilcUInt32)(_ival__))) +#else +#define SILC_32_TO_PTR(_ival__) ((void *)((SilcUInt64)(_ival__))) +#endif +/***/ + +/****d* silcutil/SILCTypes/SILC_64_TO_PTR + * + * NAME + * + * #define SILC_PTR_TO_64 ... + * + * DESCRIPTION + * + * Type casts a 64-bit integer value into a pointer. Use this to + * avoid compiler warnings when type casting integers to pointers of + * different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_64_TO_PTR(_ival__) \ + ((void *)((SilcUInt32)((SilcUInt64)(_ival__) & (SilcUInt32)0xFFFFFFFFUL))) +#else +#define SILC_64_TO_PTR(_ival__) ((void *)((SilcUInt64)(_ival__))) +#endif +/***/ + #endif /* SILCTYPES_H */