]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/openssl/e_os2.h
c556e57ca9614760922fff4c10345f3efae48ef0
[thirdparty/openssl.git] / include / openssl / e_os2.h
1 /*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #ifndef HEADER_E_OS2_H
11 # define HEADER_E_OS2_H
12
13 # include <openssl/opensslconf.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /******************************************************************************
20 * Detect operating systems. This probably needs completing.
21 * The result is that at least one OPENSSL_SYS_os macro should be defined.
22 * However, if none is defined, Unix is assumed.
23 **/
24
25 # define OPENSSL_SYS_UNIX
26
27 /* --------------------- Microsoft operating systems ---------------------- */
28
29 /*
30 * Note that MSDOS actually denotes 32-bit environments running on top of
31 * MS-DOS, such as DJGPP one.
32 */
33 # if defined(OPENSSL_SYS_MSDOS)
34 # undef OPENSSL_SYS_UNIX
35 # endif
36
37 /*
38 * For 32 bit environment, there seems to be the CygWin environment and then
39 * all the others that try to do the same thing Microsoft does...
40 */
41 /*
42 * UEFI lives here because it might be built with a Microsoft toolchain and
43 * we need to avoid the false positive match on Windows.
44 */
45 # if defined(OPENSSL_SYS_UEFI)
46 # undef OPENSSL_SYS_UNIX
47 # elif defined(OPENSSL_SYS_UWIN)
48 # undef OPENSSL_SYS_UNIX
49 # define OPENSSL_SYS_WIN32_UWIN
50 # else
51 # if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN)
52 # undef OPENSSL_SYS_UNIX
53 # define OPENSSL_SYS_WIN32_CYGWIN
54 # else
55 # if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
56 # undef OPENSSL_SYS_UNIX
57 # if !defined(OPENSSL_SYS_WIN32)
58 # define OPENSSL_SYS_WIN32
59 # endif
60 # endif
61 # if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
62 # undef OPENSSL_SYS_UNIX
63 # if !defined(OPENSSL_SYS_WIN64)
64 # define OPENSSL_SYS_WIN64
65 # endif
66 # endif
67 # if defined(OPENSSL_SYS_WINNT)
68 # undef OPENSSL_SYS_UNIX
69 # endif
70 # if defined(OPENSSL_SYS_WINCE)
71 # undef OPENSSL_SYS_UNIX
72 # endif
73 # endif
74 # endif
75
76 /* Anything that tries to look like Microsoft is "Windows" */
77 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
78 # undef OPENSSL_SYS_UNIX
79 # define OPENSSL_SYS_WINDOWS
80 # ifndef OPENSSL_SYS_MSDOS
81 # define OPENSSL_SYS_MSDOS
82 # endif
83 # endif
84
85 /*
86 * DLL settings. This part is a bit tough, because it's up to the
87 * application implementor how he or she will link the application, so it
88 * requires some macro to be used.
89 */
90 # ifdef OPENSSL_SYS_WINDOWS
91 # ifndef OPENSSL_OPT_WINDLL
92 # if defined(_WINDLL) /* This is used when building OpenSSL to
93 * indicate that DLL linkage should be used */
94 # define OPENSSL_OPT_WINDLL
95 # endif
96 # endif
97 # endif
98
99 /* ------------------------------- OpenVMS -------------------------------- */
100 # if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
101 # if !defined(OPENSSL_SYS_VMS)
102 # undef OPENSSL_SYS_UNIX
103 # endif
104 # define OPENSSL_SYS_VMS
105 # if defined(__DECC)
106 # define OPENSSL_SYS_VMS_DECC
107 # elif defined(__DECCXX)
108 # define OPENSSL_SYS_VMS_DECC
109 # define OPENSSL_SYS_VMS_DECCXX
110 # else
111 # define OPENSSL_SYS_VMS_NODECC
112 # endif
113 # endif
114
115 /* -------------------------------- Unix ---------------------------------- */
116 # ifdef OPENSSL_SYS_UNIX
117 # if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
118 # define OPENSSL_SYS_LINUX
119 # endif
120 # if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
121 # define OPENSSL_SYS_AIX
122 # endif
123 # endif
124
125 /* -------------------------------- VOS ----------------------------------- */
126 # if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
127 # define OPENSSL_SYS_VOS
128 # ifdef __HPPA__
129 # define OPENSSL_SYS_VOS_HPPA
130 # endif
131 # ifdef __IA32__
132 # define OPENSSL_SYS_VOS_IA32
133 # endif
134 # endif
135
136 /**
137 * That's it for OS-specific stuff
138 *****************************************************************************/
139
140 /* Specials for I/O an exit */
141 # ifdef OPENSSL_SYS_MSDOS
142 # define OPENSSL_UNISTD_IO <io.h>
143 # define OPENSSL_DECLARE_EXIT extern void exit(int);
144 # else
145 # define OPENSSL_UNISTD_IO OPENSSL_UNISTD
146 # define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
147 # endif
148
149 /*-
150 * Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare
151 * certain global symbols that, with some compilers under VMS, have to be
152 * defined and declared explicitly with globaldef and globalref.
153 * Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare
154 * DLL exports and imports for compilers under Win32. These are a little
155 * more complicated to use. Basically, for any library that exports some
156 * global variables, the following code must be present in the header file
157 * that declares them, before OPENSSL_EXTERN is used:
158 *
159 * #ifdef SOME_BUILD_FLAG_MACRO
160 * # undef OPENSSL_EXTERN
161 * # define OPENSSL_EXTERN OPENSSL_EXPORT
162 * #endif
163 *
164 * The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL
165 * have some generally sensible values.
166 */
167
168 # if defined(OPENSSL_SYS_VMS_NODECC)
169 # define OPENSSL_EXPORT globalref
170 # define OPENSSL_EXTERN globalref
171 # define OPENSSL_GLOBAL globaldef
172 # elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
173 # define OPENSSL_EXPORT extern __declspec(dllexport)
174 # define OPENSSL_EXTERN extern __declspec(dllimport)
175 # define OPENSSL_GLOBAL
176 # else
177 # define OPENSSL_EXPORT extern
178 # define OPENSSL_EXTERN extern
179 # define OPENSSL_GLOBAL
180 # endif
181
182 /*-
183 * Macros to allow global variables to be reached through function calls when
184 * required (if a shared library version requires it, for example.
185 * The way it's done allows definitions like this:
186 *
187 * // in foobar.c
188 * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
189 * // in foobar.h
190 * OPENSSL_DECLARE_GLOBAL(int,foobar);
191 * #define foobar OPENSSL_GLOBAL_REF(foobar)
192 */
193 # ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
194 # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
195 type *_shadow_##name(void) \
196 { static type _hide_##name=value; return &_hide_##name; }
197 # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
198 # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
199 # else
200 # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
201 # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
202 # define OPENSSL_GLOBAL_REF(name) _shadow_##name
203 # endif
204
205 # ifdef _WIN32
206 # ifdef _WIN64
207 # define ossl_ssize_t __int64
208 # define OSSL_SSIZE_MAX _I64_MAX
209 # else
210 # define ossl_ssize_t int
211 # define OSSL_SSIZE_MAX INT_MAX
212 # endif
213 # endif
214
215 # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
216 # define ossl_ssize_t int
217 # define OSSL_SSIZE_MAX INT_MAX
218 # endif
219
220 # ifndef ossl_ssize_t
221 # define ossl_ssize_t ssize_t
222 # define OSSL_SSIZE_MAX SSIZE_MAX
223 # endif
224
225 # ifdef DEBUG_UNUSED
226 # define __owur __attribute__((__warn_unused_result__))
227 # else
228 # define __owur
229 # endif
230
231 /* Standard integer types */
232 # if defined(OPENSSL_SYS_UEFI)
233 typedef INT8 int8_t;
234 typedef UINT8 uint8_t;
235 typedef INT16 int16_t;
236 typedef UINT16 uint16_t;
237 typedef INT32 int32_t;
238 typedef UINT32 uint32_t;
239 typedef INT64 int64_t;
240 typedef UINT64 uint64_t;
241 # define PRIu64 "%Lu"
242 # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
243 defined(__osf__) || defined(__sgi) || defined(__hpux) || \
244 defined(OPENSSL_SYS_VMS)
245 # include <inttypes.h>
246 # elif defined(_MSC_VER) && _MSC_VER<=1500
247 /*
248 * minimally required typdefs for systems not supporting inttypes.h or
249 * stdint.h: currently just older VC++
250 */
251 typedef signed char int8_t;
252 typedef unsigned char uint8_t;
253 typedef short int16_t;
254 typedef unsigned short uint16_t;
255 typedef int int32_t;
256 typedef unsigned int uint32_t;
257 typedef __int64 int64_t;
258 typedef unsigned __int64 uint64_t;
259 # else
260 # include <stdint.h>
261 # endif
262
263 /*
264 * We need a format operator for some client tools for uint64_t. If inttypes.h
265 * isn't available or did not define it, just go with hard-coded.
266 */
267 # ifndef PRIu64
268 # ifdef SIXTY_FOUR_BIT_LONG
269 # define PRIu64 "lu"
270 # else
271 # define PRIu64 "llu"
272 # endif
273 # endif
274
275 /* ossl_inline: portable inline definition usable in public headers */
276 # if !defined(inline) && !defined(__cplusplus)
277 # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
278 /* just use inline */
279 # define ossl_inline inline
280 # elif defined(__GNUC__) && __GNUC__>=2
281 # define ossl_inline __inline__
282 # elif defined(_MSC_VER)
283 /*
284 * Visual Studio: inline is available in C++ only, however
285 * __inline is available for C, see
286 * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
287 */
288 # define ossl_inline __inline
289 # else
290 # define ossl_inline
291 # endif
292 # else
293 # define ossl_inline inline
294 # endif
295
296 #ifdef __cplusplus
297 }
298 #endif
299 #endif