740cf5561ca33fb95523d7bca9d98068a16c9dab
[openssl.git] / include / openssl / e_os2.h
1 /*
2  * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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 OPENSSL_E_OS2_H
11 # define OPENSSL_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 #   define OPENSSL_SYS_WIN32_CYGWIN
53 #  else
54 #   if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
55 #    undef OPENSSL_SYS_UNIX
56 #    if !defined(OPENSSL_SYS_WIN32)
57 #     define OPENSSL_SYS_WIN32
58 #    endif
59 #   endif
60 #   if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
61 #    undef OPENSSL_SYS_UNIX
62 #    if !defined(OPENSSL_SYS_WIN64)
63 #     define OPENSSL_SYS_WIN64
64 #    endif
65 #   endif
66 #   if defined(OPENSSL_SYS_WINNT)
67 #    undef OPENSSL_SYS_UNIX
68 #   endif
69 #   if defined(OPENSSL_SYS_WINCE)
70 #    undef OPENSSL_SYS_UNIX
71 #   endif
72 #  endif
73 # endif
74
75 /* Anything that tries to look like Microsoft is "Windows" */
76 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
77 #  undef OPENSSL_SYS_UNIX
78 #  define OPENSSL_SYS_WINDOWS
79 #  ifndef OPENSSL_SYS_MSDOS
80 #   define OPENSSL_SYS_MSDOS
81 #  endif
82 # endif
83
84 /*
85  * DLL settings.  This part is a bit tough, because it's up to the
86  * application implementor how he or she will link the application, so it
87  * requires some macro to be used.
88  */
89 # ifdef OPENSSL_SYS_WINDOWS
90 #  ifndef OPENSSL_OPT_WINDLL
91 #   if defined(_WINDLL)         /* This is used when building OpenSSL to
92                                  * indicate that DLL linkage should be used */
93 #    define OPENSSL_OPT_WINDLL
94 #   endif
95 #  endif
96 # endif
97
98 /* ------------------------------- OpenVMS -------------------------------- */
99 # if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
100 #  if !defined(OPENSSL_SYS_VMS)
101 #   undef OPENSSL_SYS_UNIX
102 #  endif
103 #  define OPENSSL_SYS_VMS
104 #  if defined(__DECC)
105 #   define OPENSSL_SYS_VMS_DECC
106 #  elif defined(__DECCXX)
107 #   define OPENSSL_SYS_VMS_DECC
108 #   define OPENSSL_SYS_VMS_DECCXX
109 #  else
110 #   define OPENSSL_SYS_VMS_NODECC
111 #  endif
112 # endif
113
114 /* -------------------------------- Unix ---------------------------------- */
115 # ifdef OPENSSL_SYS_UNIX
116 #  if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
117 #   define OPENSSL_SYS_LINUX
118 #  endif
119 #  if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
120 #   define OPENSSL_SYS_AIX
121 #  endif
122 # endif
123
124 /* -------------------------------- VOS ----------------------------------- */
125 # if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
126 #  define OPENSSL_SYS_VOS
127 #  ifdef __HPPA__
128 #   define OPENSSL_SYS_VOS_HPPA
129 #  endif
130 #  ifdef __IA32__
131 #   define OPENSSL_SYS_VOS_IA32
132 #  endif
133 # endif
134
135 /**
136  * That's it for OS-specific stuff
137  *****************************************************************************/
138
139 /*-
140  * OPENSSL_EXTERN is normally used to declare a symbol with possible extra
141  * attributes to handle its presence in a shared library.
142  * OPENSSL_EXPORT is used to define a symbol with extra possible attributes
143  * to make it visible in a shared library.
144  * Care needs to be taken when a header file is used both to declare and
145  * define symbols.  Basically, for any library that exports some global
146  * variables, the following code must be present in the header file that
147  * declares them, before OPENSSL_EXTERN is used:
148  *
149  * #ifdef SOME_BUILD_FLAG_MACRO
150  * # undef OPENSSL_EXTERN
151  * # define OPENSSL_EXTERN OPENSSL_EXPORT
152  * #endif
153  *
154  * The default is to have OPENSSL_EXPORT and OPENSSL_EXTERN
155  * have some generally sensible values.
156  */
157
158 # if defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
159 #  define OPENSSL_EXPORT extern __declspec(dllexport)
160 #  define OPENSSL_EXTERN extern __declspec(dllimport)
161 # else
162 #  define OPENSSL_EXPORT extern
163 #  define OPENSSL_EXTERN extern
164 # endif
165
166 # ifdef _WIN32
167 #  ifdef _WIN64
168 #   define ossl_ssize_t __int64
169 #   define OSSL_SSIZE_MAX _I64_MAX
170 #  else
171 #   define ossl_ssize_t int
172 #   define OSSL_SSIZE_MAX INT_MAX
173 #  endif
174 # endif
175
176 # if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
177 #  define ossl_ssize_t INTN
178 #  define OSSL_SSIZE_MAX MAX_INTN
179 # endif
180
181 # ifndef ossl_ssize_t
182 #  define ossl_ssize_t ssize_t
183 #  if defined(SSIZE_MAX)
184 #   define OSSL_SSIZE_MAX SSIZE_MAX
185 #  elif defined(_POSIX_SSIZE_MAX)
186 #   define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
187 #  else
188 #   define OSSL_SSIZE_MAX ((ssize_t)(SIZE_MAX>>1))
189 #  endif
190 # endif
191
192 # ifdef DEBUG_UNUSED
193 #  define __owur __attribute__((__warn_unused_result__))
194 # else
195 #  define __owur
196 # endif
197
198 /* Standard integer types */
199 # define OPENSSL_NO_INTTYPES_H
200 # define OPENSSL_NO_STDINT_H
201 # if defined(OPENSSL_SYS_UEFI)
202 typedef INT8 int8_t;
203 typedef UINT8 uint8_t;
204 typedef INT16 int16_t;
205 typedef UINT16 uint16_t;
206 typedef INT32 int32_t;
207 typedef UINT32 uint32_t;
208 typedef INT64 int64_t;
209 typedef UINT64 uint64_t;
210 # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
211      defined(__osf__) || defined(__sgi) || defined(__hpux) || \
212      defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
213 #  include <inttypes.h>
214 #  undef OPENSSL_NO_INTTYPES_H
215 /* Because the specs say that inttypes.h includes stdint.h if present */
216 #  undef OPENSSL_NO_STDINT_H
217 # elif defined(_MSC_VER) && _MSC_VER<=1500
218 /*
219  * minimally required typdefs for systems not supporting inttypes.h or
220  * stdint.h: currently just older VC++
221  */
222 typedef signed char int8_t;
223 typedef unsigned char uint8_t;
224 typedef short int16_t;
225 typedef unsigned short uint16_t;
226 typedef int int32_t;
227 typedef unsigned int uint32_t;
228 typedef __int64 int64_t;
229 typedef unsigned __int64 uint64_t;
230 # else
231 #  include <stdint.h>
232 #  undef OPENSSL_NO_STDINT_H
233 # endif
234
235 /* ossl_inline: portable inline definition usable in public headers */
236 # if !defined(inline) && !defined(__cplusplus)
237 #  if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
238    /* just use inline */
239 #   define ossl_inline inline
240 #  elif defined(__GNUC__) && __GNUC__>=2
241 #   define ossl_inline __inline__
242 #  elif defined(_MSC_VER)
243   /*
244    * Visual Studio: inline is available in C++ only, however
245    * __inline is available for C, see
246    * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
247    */
248 #   define ossl_inline __inline
249 #  else
250 #   define ossl_inline
251 #  endif
252 # else
253 #  define ossl_inline inline
254 # endif
255
256 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
257 #  define ossl_noreturn _Noreturn
258 # elif defined(__GNUC__) && __GNUC__ >= 2
259 #  define ossl_noreturn __attribute__((noreturn))
260 # else
261 #  define ossl_noreturn
262 # endif
263
264 /* ossl_unused: portable unused attribute for use in public headers */
265 # if defined(__GNUC__)
266 #  define ossl_unused __attribute__((unused))
267 # else
268 #  define ossl_unused
269 # endif
270
271 #ifdef  __cplusplus
272 }
273 #endif
274 #endif