|
| 1 | +/* |
| 2 | + --------------------------------------------------------------------------- |
| 3 | + Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved. |
| 4 | +
|
| 5 | + (a few lines added by Soeren S. Thomsen, October 2008) |
| 6 | +
|
| 7 | + LICENSE TERMS |
| 8 | +
|
| 9 | + The redistribution and use of this software (with or without changes) |
| 10 | + is allowed without the payment of fees or royalties provided that: |
| 11 | +
|
| 12 | + 1. source code distributions include the above copyright notice, this |
| 13 | + list of conditions and the following disclaimer; |
| 14 | +
|
| 15 | + 2. binary distributions include the above copyright notice, this list |
| 16 | + of conditions and the following disclaimer in their documentation; |
| 17 | +
|
| 18 | + 3. the name of the copyright holder is not used to endorse products |
| 19 | + built using this software without specific written permission. |
| 20 | +
|
| 21 | + DISCLAIMER |
| 22 | +
|
| 23 | + This software is provided 'as is' with no explicit or implied warranties |
| 24 | + in respect of its properties, including, but not limited to, correctness |
| 25 | + and/or fitness for purpose. |
| 26 | + --------------------------------------------------------------------------- |
| 27 | + Issue Date: 20/12/2007 |
| 28 | +
|
| 29 | + The unsigned integer types defined here are of the form uint_<nn>t where |
| 30 | + <nn> is the length of the type; for example, the unsigned 32-bit type is |
| 31 | + 'uint_32t'. These are NOT the same as the 'C99 integer types' that are |
| 32 | + defined in the inttypes.h and stdint.h headers since attempts to use these |
| 33 | + types have shown that support for them is still highly variable. However, |
| 34 | + since the latter are of the form uint<nn>_t, a regular expression search |
| 35 | + and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t') |
| 36 | + can be used to convert the types used here to the C99 standard types. |
| 37 | +*/ |
| 38 | + |
| 39 | +#ifndef _BRG_TYPES_H |
| 40 | +#define _BRG_TYPES_H |
| 41 | + |
| 42 | +#if defined(__cplusplus) |
| 43 | +extern "C" { |
| 44 | +#endif |
| 45 | + |
| 46 | +#include <limits.h> |
| 47 | + |
| 48 | +#if defined( _MSC_VER ) && ( _MSC_VER >= 1300 ) |
| 49 | +# include <stddef.h> |
| 50 | +# define ptrint_t intptr_t |
| 51 | +#elif defined( __GNUC__ ) && ( __GNUC__ >= 3 ) |
| 52 | +# include <stdint.h> |
| 53 | +# define ptrint_t intptr_t |
| 54 | +#else |
| 55 | +# define ptrint_t int |
| 56 | +#endif |
| 57 | + |
| 58 | +#ifndef BRG_UI8 |
| 59 | +# define BRG_UI8 |
| 60 | +# if UCHAR_MAX == 255u |
| 61 | + typedef unsigned char uint_8t; |
| 62 | +# else |
| 63 | +# error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h |
| 64 | +# endif |
| 65 | +#endif |
| 66 | + |
| 67 | +#ifndef BRG_UI16 |
| 68 | +# define BRG_UI16 |
| 69 | +# if USHRT_MAX == 65535u |
| 70 | + typedef unsigned short uint_16t; |
| 71 | +# else |
| 72 | +# error Please define uint_16t as a 16-bit unsigned short type in brg_types.h |
| 73 | +# endif |
| 74 | +#endif |
| 75 | + |
| 76 | +#ifndef BRG_UI32 |
| 77 | +# define BRG_UI32 |
| 78 | +# if UINT_MAX == 4294967295u |
| 79 | +# define li_32(h) 0x##h##u |
| 80 | + typedef unsigned int uint_32t; |
| 81 | +# elif ULONG_MAX == 4294967295u |
| 82 | +# define li_32(h) 0x##h##ul |
| 83 | + typedef unsigned long uint_32t; |
| 84 | +# elif defined( _CRAY ) |
| 85 | +# error This code needs 32-bit data types, which Cray machines do not provide |
| 86 | +# else |
| 87 | +# error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h |
| 88 | +# endif |
| 89 | +#endif |
| 90 | + |
| 91 | +#ifndef BRG_UI64 |
| 92 | +# if defined( __BORLANDC__ ) && !defined( __MSDOS__ ) |
| 93 | +# define BRG_UI64 |
| 94 | +# define li_64(h) 0x##h##ui64 |
| 95 | + typedef unsigned __int64 uint_64t; |
| 96 | +# elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */ |
| 97 | +# define BRG_UI64 |
| 98 | +# define li_64(h) 0x##h##ui64 |
| 99 | + typedef unsigned __int64 uint_64t; |
| 100 | +# elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful |
| 101 | +# define BRG_UI64 |
| 102 | +# define li_64(h) 0x##h##ull |
| 103 | + typedef unsigned long long uint_64t; |
| 104 | +# elif defined( __MVS__ ) |
| 105 | +# define BRG_UI64 |
| 106 | +# define li_64(h) 0x##h##ull |
| 107 | + typedef unsigned int long long uint_64t; |
| 108 | +# elif defined( UINT_MAX ) && UINT_MAX > 4294967295u |
| 109 | +# if UINT_MAX == 18446744073709551615u |
| 110 | +# define BRG_UI64 |
| 111 | +# define li_64(h) 0x##h##u |
| 112 | + typedef unsigned int uint_64t; |
| 113 | +# endif |
| 114 | +# elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u |
| 115 | +# if ULONG_MAX == 18446744073709551615ul |
| 116 | +# define BRG_UI64 |
| 117 | +# define li_64(h) 0x##h##ul |
| 118 | + typedef unsigned long uint_64t; |
| 119 | +# endif |
| 120 | +# elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u |
| 121 | +# if ULLONG_MAX == 18446744073709551615ull |
| 122 | +# define BRG_UI64 |
| 123 | +# define li_64(h) 0x##h##ull |
| 124 | + typedef unsigned long long uint_64t; |
| 125 | +# endif |
| 126 | +# elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u |
| 127 | +# if ULONG_LONG_MAX == 18446744073709551615ull |
| 128 | +# define BRG_UI64 |
| 129 | +# define li_64(h) 0x##h##ull |
| 130 | + typedef unsigned long long uint_64t; |
| 131 | +# endif |
| 132 | +# endif |
| 133 | +#endif |
| 134 | + |
| 135 | +#if !defined( BRG_UI64 ) |
| 136 | +# if defined( NEED_UINT_64T ) |
| 137 | +# define BRG_UI64 |
| 138 | +# define li_64(h) 0x##h##ull |
| 139 | + typedef unsigned long long uint_64t; |
| 140 | + /*# error Please define uint_64t as an unsigned 64 bit type in brg_types.h*/ |
| 141 | +# endif |
| 142 | +#endif |
| 143 | + |
| 144 | +#ifndef RETURN_VALUES |
| 145 | +# define RETURN_VALUES |
| 146 | +# if defined( DLL_EXPORT ) |
| 147 | +# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) |
| 148 | +# define VOID_RETURN __declspec( dllexport ) void __stdcall |
| 149 | +# define INT_RETURN __declspec( dllexport ) int __stdcall |
| 150 | +# elif defined( __GNUC__ ) |
| 151 | +# define VOID_RETURN __declspec( __dllexport__ ) void |
| 152 | +# define INT_RETURN __declspec( __dllexport__ ) int |
| 153 | +# else |
| 154 | +# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers |
| 155 | +# endif |
| 156 | +# elif defined( DLL_IMPORT ) |
| 157 | +# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) |
| 158 | +# define VOID_RETURN __declspec( dllimport ) void __stdcall |
| 159 | +# define INT_RETURN __declspec( dllimport ) int __stdcall |
| 160 | +# elif defined( __GNUC__ ) |
| 161 | +# define VOID_RETURN __declspec( __dllimport__ ) void |
| 162 | +# define INT_RETURN __declspec( __dllimport__ ) int |
| 163 | +# else |
| 164 | +# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers |
| 165 | +# endif |
| 166 | +# elif defined( __WATCOMC__ ) |
| 167 | +# define VOID_RETURN void __cdecl |
| 168 | +# define INT_RETURN int __cdecl |
| 169 | +# else |
| 170 | +# define VOID_RETURN void |
| 171 | +# define INT_RETURN int |
| 172 | +# endif |
| 173 | +#endif |
| 174 | + |
| 175 | +/* These defines are used to detect and set the memory alignment of pointers. |
| 176 | + Note that offsets are in bytes. |
| 177 | +
|
| 178 | + ALIGN_OFFSET(x,n) return the positive or zero offset of |
| 179 | + the memory addressed by the pointer 'x' |
| 180 | + from an address that is aligned on an |
| 181 | + 'n' byte boundary ('n' is a power of 2) |
| 182 | +
|
| 183 | + ALIGN_FLOOR(x,n) return a pointer that points to memory |
| 184 | + that is aligned on an 'n' byte boundary |
| 185 | + and is not higher than the memory address |
| 186 | + pointed to by 'x' ('n' is a power of 2) |
| 187 | +
|
| 188 | + ALIGN_CEIL(x,n) return a pointer that points to memory |
| 189 | + that is aligned on an 'n' byte boundary |
| 190 | + and is not lower than the memory address |
| 191 | + pointed to by 'x' ('n' is a power of 2) |
| 192 | +*/ |
| 193 | + |
| 194 | +#define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1)) |
| 195 | +#define ALIGN_FLOOR(x,n) ((uint_8t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1))) |
| 196 | +#define ALIGN_CEIL(x,n) ((uint_8t*)(x) + (-((ptrint_t)(x)) & ((n) - 1))) |
| 197 | + |
| 198 | +/* These defines are used to declare buffers in a way that allows |
| 199 | + faster operations on longer variables to be used. In all these |
| 200 | + defines 'size' must be a power of 2 and >= 8. NOTE that the |
| 201 | + buffer size is in bytes but the type length is in bits |
| 202 | +
|
| 203 | + UNIT_TYPEDEF(x,size) declares a variable 'x' of length |
| 204 | + 'size' bits |
| 205 | +
|
| 206 | + BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize' |
| 207 | + bytes defined as an array of variables |
| 208 | + each of 'size' bits (bsize must be a |
| 209 | + multiple of size / 8) |
| 210 | +
|
| 211 | + UNIT_CAST(x,size) casts a variable to a type of |
| 212 | + length 'size' bits |
| 213 | +
|
| 214 | + UPTR_CAST(x,size) casts a pointer to a pointer to a |
| 215 | + varaiable of length 'size' bits |
| 216 | +*/ |
| 217 | + |
| 218 | +#define UI_TYPE(size) uint_##size##t |
| 219 | +#define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x |
| 220 | +#define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)] |
| 221 | +#define UNIT_CAST(x,size) ((UI_TYPE(size) )(x)) |
| 222 | +#define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x)) |
| 223 | + |
| 224 | + /* Added by Soeren S. Thomsen (begin) */ |
| 225 | +#define u8 uint_8t |
| 226 | +#define u32 uint_32t |
| 227 | +#define u64 uint_64t |
| 228 | + /* (end) */ |
| 229 | + |
| 230 | +#if defined(__cplusplus) |
| 231 | +} |
| 232 | +#endif |
| 233 | + |
| 234 | +#endif |
0 commit comments