hamsterdb Embedded Database  2.1.7
types.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2014 Christoph Rupp (chris@crupp.de).
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
24 #ifndef HAM_TYPES_H__
25 #define HAM_TYPES_H__
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /*
32  * Check the operating system and word size
33  */
34 #ifdef WIN32
35 # undef HAM_OS_WIN32
36 # define HAM_OS_WIN32 1
37 # ifdef WIN64
38 # undef HAM_64BIT
39 # define HAM_64BIT 1
40 # elif WIN32
41 # undef HAM_32BIT
42 # define HAM_32BIT 1
43 # else
44 # error "Neither WIN32 nor WIN64 defined!"
45 # endif
46 #else /* posix? */
47 # undef HAM_OS_POSIX
48 # define HAM_OS_POSIX 1
49 # if defined(__LP64__) || defined(__LP64) || __WORDSIZE == 64
50 # undef HAM_64BIT
51 # define HAM_64BIT 1
52 # else
53 # undef HAM_32BIT
54 # define HAM_32BIT 1
55 # endif
56 #endif
57 
58 #if defined(HAM_OS_POSIX) && defined(HAM_OS_WIN32)
59 # error "Unknown arch - neither HAM_OS_POSIX nor HAM_OS_WIN32 defined"
60 #endif
61 
62 /*
63  * windows.h is needed for for HANDLE
64  */
65 #if defined(HAM_OS_WIN32)
66 # define WIN32_MEAN_AND_LEAN
67 # include <winsock2.h>
68 # include <windows.h>
69 #endif
70 
71 /*
72  * improve memory debugging on WIN32 by using crtdbg.h (only MSVC
73  * compiler and debug builds!)
74  *
75  * make sure crtdbg.h is loaded before malloc.h!
76  */
77 #if defined(_MSC_VER) && defined(HAM_OS_WIN32)
78 # if (defined(WIN32) || defined(__WIN32)) && !defined(UNDER_CE)
79 # if defined(DEBUG) || defined(_DEBUG)
80 # ifndef _CRTDBG_MAP_ALLOC
81 # define _CRTDBG_MAP_ALLOC 1
82 # endif
83 # endif
84 # include <crtdbg.h>
85 # include <malloc.h>
86 # endif
87 #endif
88 
89 /*
90  * Create the EXPORT macro for Microsoft Visual C++
91  */
92 #ifndef HAM_EXPORT
93 # ifdef _MSC_VER
94 # define HAM_EXPORT __declspec(dllexport)
95 # else
96 # define HAM_EXPORT extern
97 # endif
98 #endif
99 
100 /*
101  * The default calling convention is cdecl
102  */
103 #ifndef HAM_CALLCONV
104 # define HAM_CALLCONV
105 #endif
106 
110 #ifdef HAM_32BIT
111 # ifdef _MSC_VER
112 typedef signed __int64 ham_s64_t;
113 typedef unsigned __int64 ham_u64_t;
114 # else
115 typedef signed long long ham_s64_t;
116 typedef unsigned long long ham_u64_t;
117 # endif
118 typedef signed int ham_s32_t;
119 typedef unsigned int ham_u32_t;
120 typedef signed short ham_s16_t;
121 typedef unsigned short ham_u16_t;
122 typedef signed char ham_s8_t;
123 typedef unsigned char ham_u8_t;
124 #endif
125 
130 #ifdef HAM_64BIT
131 # ifdef _MSC_VER
132 typedef signed __int64 ham_s64_t;
133 typedef unsigned __int64 ham_u64_t;
134 # else
135 typedef signed long ham_s64_t;
136 typedef unsigned long ham_u64_t;
137 # endif
138 typedef signed int ham_s32_t;
139 typedef unsigned int ham_u32_t;
140 typedef signed short ham_s16_t;
141 typedef unsigned short ham_u16_t;
142 typedef signed char ham_s8_t;
143 typedef unsigned char ham_u8_t;
144 #endif
145 
146 /*
147  * Undefine macros to avoid macro redefinitions
148  */
149 #undef HAM_INVALID_FD
150 #undef HAM_FALSE
151 #undef HAM_TRUE
152 
153 /*
154  * typedefs for posix
155  */
156 #ifdef HAM_OS_POSIX
157 typedef int ham_fd_t;
158 typedef int ham_socket_t;
159 # define HAM_INVALID_FD (-1)
160 #endif
161 
162 /*
163  * typedefs for Windows 32- and 64-bit
164  */
165 #ifdef HAM_OS_WIN32
166 # ifdef CYGWIN
167 typedef int ham_fd_t;
168 typedef int ham_socket_t;
169 # else
170 typedef HANDLE ham_fd_t;
171 typedef SOCKET ham_socket_t;
172 # endif
173 # define HAM_INVALID_FD (0)
174 #endif
175 
179 typedef int ham_bool_t;
180 #define HAM_FALSE 0
181 #define HAM_TRUE (!HAM_FALSE)
182 
186 typedef int ham_status_t;
187 
191 #define HAM_MAX_U32 (~(ham_u32_t)0)
192 #define HAM_MAX_SIZE_T (~(ham_u32_t)0)
193 
194 
195 #ifdef __cplusplus
196 } // extern "C"
197 #endif
198 
199 #endif /* HAM_TYPES_H__ */