OSDN Git Service

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