X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/5892fd39c789b9207fe799e91080dbef773d30cb..e3afa470a387e2726de5541e9871ccb2e9915a83:/bits.h diff --git a/bits.h b/bits.h index 4618589..1b9f485 100644 --- a/bits.h +++ b/bits.h @@ -7,7 +7,7 @@ * (c) 1998 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * @@ -15,12 +15,12 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with mLib; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, @@ -112,7 +112,7 @@ */ typedef unsigned short uint16; -typedef unsigned char octet; +typedef unsigned char octet, uint8; /* --- WARNING! --- * * @@ -126,11 +126,76 @@ typedef unsigned char octet; #define MASK8 0xffu #define MASK16 0xffffu +#define MASK16_L MASK16 +#define MASK16_B MASK16 #define MASK24 0xffffffu +#define MASK24_L MASK24 +#define MASK24_B MASK24 #define MASK32 0xffffffffu +#define MASK32_L MASK32 +#define MASK32_B MASK32 #ifdef HAVE_UINT64 # define MASK64 MLIB_BITS_EXTENSION 0xffffffffffffffffu +# define MASK64_L MASK64 +# define MASK64_B MASK64 +#endif + +/* --- Sizes --- */ + +#define SZ_8 1 +#define SZ_16 2 +#define SZ_16_L 2 +#define SZ_16_B 2 +#define SZ_24 3 +#define SZ_24_L 3 +#define SZ_24_B 3 +#define SZ_32 4 +#define SZ_32_L 4 +#define SZ_32_B 4 + +#ifdef HAVE_UINT64 +# define SZ_64 8 +# define SZ_64_L 8 +# define SZ_64_B 8 +#endif + +/* --- Type aliases --- */ + +#define TY_U8 octet +#define TY_U16 uint16 +#define TY_U16_L uint16 +#define TY_U16_B uint16 +#define TY_U24 uint24 +#define TY_U24_L uint24 +#define TY_U24_B uint24 +#define TY_U32 uint32 +#define TY_U32_L uint32 +#define TY_U32_B uint32 + +#ifdef HAVE_UINT64 +# define TY_U64 uint64 +# define TY_U64_L uint64 +# define TY_U64_B uint64 +#endif + +/* --- List macros --- */ + +#ifdef HAVE_UINT64 +# define DOUINTCONV(_) \ + _(8, 8, 8) \ + _(16, 16, 16) _(16, 16_L, 16l) _(16, 16_B, 16b) \ + _(24, 24, 24) _(24, 24_L, 24l) _(24, 24_B, 24b) \ + _(32, 32, 32) _(32, 32_L, 32l) _(32, 32_B, 32b) \ + _(64, 64, 64) _(64, 64_L, 64l) _(64, 64_B, 64b) +# define DOUINTSZ(_) _(8) _(16) _(24) _(32) _(64) +#else +# define DOUINTCONV(_) \ + _(8, 8, 8) \ + _(16, 16, 16) _(16, 16_L, 16l) _(16, 16_B, 16b) \ + _(24, 24, 24) _(24, 24_L, 24l) _(24, 24_B, 24b) \ + _(32, 32, 32) _(32, 32_L, 32l) _(32, 32_B, 32b) +# define DOUINTSZ(_) _(8) _(16) _(24) _(32) #endif /* --- Type coercions --- */ @@ -277,11 +342,11 @@ typedef unsigned char octet; #define LOAD24_B(p) \ (((uint24)GETBYTE((p), 0) << 16) | \ - ((uint24)GETBYTE((p), 1) << 8) | \ - ((uint24)GETBYTE((p), 2) << 0)) + ((uint24)GETBYTE((p), 1) << 8) | \ + ((uint24)GETBYTE((p), 2) << 0)) #define LOAD24_L(p) \ - (((uint24)GETBYTE((p), 0) << 0) | \ - ((uint24)GETBYTE((p), 1) << 8) | \ + (((uint24)GETBYTE((p), 0) << 0) | \ + ((uint24)GETBYTE((p), 1) << 8) | \ ((uint24)GETBYTE((p), 2) << 16)) #define LOAD24(p) LOAD24_B((p)) @@ -298,11 +363,11 @@ typedef unsigned char octet; #define LOAD32_B(p) \ (((uint32)GETBYTE((p), 0) << 24) | \ ((uint32)GETBYTE((p), 1) << 16) | \ - ((uint32)GETBYTE((p), 2) << 8) | \ - ((uint32)GETBYTE((p), 3) << 0)) + ((uint32)GETBYTE((p), 2) << 8) | \ + ((uint32)GETBYTE((p), 3) << 0)) #define LOAD32_L(p) \ - (((uint32)GETBYTE((p), 0) << 0) | \ - ((uint32)GETBYTE((p), 1) << 8) | \ + (((uint32)GETBYTE((p), 0) << 0) | \ + ((uint32)GETBYTE((p), 1) << 8) | \ ((uint32)GETBYTE((p), 2) << 16) | \ ((uint32)GETBYTE((p), 3) << 24)) #define LOAD32(p) LOAD32_B((p)) @@ -440,7 +505,7 @@ typedef unsigned char octet; #else # define X64(x, y) { 0x##x, 0x##y } #endif - + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus