blob: eafa8623aabe4ca009c254353636e0310d2add36 [file] [log] [blame]
Rich Salzb6cff312016-05-17 17:38:18 -04001/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00003 *
Rich Salzb6cff312016-05-17 17:38:18 -04004 * 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
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00008 */
9
10#ifndef HEADER_E_OS_H
Matt Caswell0f113f32015-01-22 03:40:55 +000011# define HEADER_E_OS_H
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000012
Matt Caswell0f113f32015-01-22 03:40:55 +000013# include <openssl/opensslconf.h>
Bodo Möller06018c41999-06-10 08:12:20 +000014
Matt Caswell0f113f32015-01-22 03:40:55 +000015# include <openssl/e_os2.h>
16/*
17 * <openssl/e_os2.h> contains what we can justify to make visible to the
18 * outside; this file e_os.h is not part of the exported interface.
19 */
Bodo Möllerfa470a81999-05-15 13:26:11 +000020
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000021#ifdef __cplusplus
22extern "C" {
23#endif
24
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000025/* Used to checking reference counts, most while doing perl5 stuff :-) */
Rich Salzf3f1cf82016-01-30 12:04:25 -050026# if defined(OPENSSL_NO_STDIO)
Rich Salzf3f1cf82016-01-30 12:04:25 -050027# if defined(REF_PRINT)
28# error "REF_PRINT requires stdio"
29# endif
30# endif
31
Andy Polyakov463a7b82016-04-06 12:47:35 +020032# if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
Rich Salzf3f1cf82016-01-30 12:04:25 -050033# define REF_ASSERT_ISNT(test) \
Rich Salz040d43b2016-02-13 14:20:43 -050034 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
Rich Salzf3f1cf82016-01-30 12:04:25 -050035# else
36# define REF_ASSERT_ISNT(i)
37# endif
Matt Caswell0f113f32015-01-22 03:40:55 +000038# ifdef REF_PRINT
Rich Salzf3f1cf82016-01-30 12:04:25 -050039# define REF_PRINT_COUNT(a, b) \
40 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
41# else
42# define REF_PRINT_COUNT(a, b)
David Woodhouse984d6c62015-09-11 14:56:32 -040043# endif
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000044
Rich Salza773b522016-02-13 22:33:56 -050045# define osslargused(x) (void)x
Rich Salz040d43b2016-02-13 14:20:43 -050046# define OPENSSL_CONF "openssl.cnf"
Rich Salza773b522016-02-13 22:33:56 -050047
Matt Caswell0f113f32015-01-22 03:40:55 +000048# ifndef DEVRANDOM
49/*
50 * set this to a comma-separated list of 'random' device files to try out. My
51 * default, we will try to read at least one of these files
52 */
53# define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
54# endif
Benjamin Kaduk0423f812016-01-12 18:02:16 -060055# if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
Matt Caswell0f113f32015-01-22 03:40:55 +000056/*
57 * set this to a comma-separated list of 'egd' sockets to try out. These
58 * sockets will be tried in the order listed in case accessing the device
59 * files listed in DEVRANDOM did not return enough entropy.
60 */
61# define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
62# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000063
Matt Caswell0f113f32015-01-22 03:40:55 +000064# if defined(OPENSSL_SYS_VXWORKS)
Richard Levitte3e83e682002-02-14 15:37:38 +000065# define NO_SYS_PARAM_H
66# define NO_CHMOD
67# define NO_SYSLOG
Matt Caswell0f113f32015-01-22 03:40:55 +000068# endif
69
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000070/********************************************************************
71 The Microsoft section
72 ********************************************************************/
Matt Caswell0f113f32015-01-22 03:40:55 +000073# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
Ulf Möllerb8384652000-01-20 23:59:24 +000074# define WIN32
Matt Caswell0f113f32015-01-22 03:40:55 +000075# endif
76# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
Richard Levittecf1b7d92001-02-19 16:06:34 +000077# define WINDOWS
Matt Caswell0f113f32015-01-22 03:40:55 +000078# endif
79# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
Richard Levittecf1b7d92001-02-19 16:06:34 +000080# define MSDOS
Matt Caswell0f113f32015-01-22 03:40:55 +000081# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000082
David Woodhouse4d60c7e2015-09-08 22:51:17 -040083# if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
Andy Polyakov9a1e34e1999-12-19 16:07:19 +000084# define GETPID_IS_MEANINGLESS
Matt Caswell0f113f32015-01-22 03:40:55 +000085# endif
Andy Polyakov9a1e34e1999-12-19 16:07:19 +000086
Matt Caswell0f113f32015-01-22 03:40:55 +000087# ifdef WIN32
88# define NO_SYS_UN_H
89# define get_last_sys_error() GetLastError()
90# define clear_sys_error() SetLastError(0)
91# if !defined(WINNT)
92# define WIN_CONSOLE_BUG
93# endif
94# else
95# define get_last_sys_error() errno
96# define clear_sys_error() errno=0
97# endif
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000098
Matt Caswell0f113f32015-01-22 03:40:55 +000099# if defined(WINDOWS)
100# define get_last_socket_error() WSAGetLastError()
101# define clear_socket_error() WSASetLastError(0)
102# define readsocket(s,b,n) recv((s),(b),(n),0)
103# define writesocket(s,b,n) send((s),(b),(n),0)
104# elif defined(__DJGPP__)
105# define WATT32
Richard Levitte2c25ebd2016-05-10 14:41:19 +0200106# define WATT32_NO_OLDIES
Matt Caswell0f113f32015-01-22 03:40:55 +0000107# define get_last_socket_error() errno
108# define clear_socket_error() errno=0
109# define closesocket(s) close_s(s)
110# define readsocket(s,b,n) read_s(s,b,n)
111# define writesocket(s,b,n) send(s,b,n,0)
112# elif defined(OPENSSL_SYS_VMS)
113# define get_last_socket_error() errno
114# define clear_socket_error() errno=0
115# define ioctlsocket(a,b,c) ioctl(a,b,c)
116# define closesocket(s) close(s)
117# define readsocket(s,b,n) recv((s),(b),(n),0)
118# define writesocket(s,b,n) send((s),(b),(n),0)
119# elif defined(OPENSSL_SYS_VXWORKS)
120# define get_last_socket_error() errno
121# define clear_socket_error() errno=0
122# define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
123# define closesocket(s) close(s)
124# define readsocket(s,b,n) read((s),(b),(n))
125# define writesocket(s,b,n) write((s),(char *)(b),(n))
Matt Caswell0f113f32015-01-22 03:40:55 +0000126# else
127# define get_last_socket_error() errno
128# define clear_socket_error() errno=0
129# define ioctlsocket(a,b,c) ioctl(a,b,c)
130# define closesocket(s) close(s)
131# define readsocket(s,b,n) read((s),(b),(n))
132# define writesocket(s,b,n) write((s),(b),(n))
133# endif
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000134
Matt Caswell0f113f32015-01-22 03:40:55 +0000135# if (defined(WINDOWS) || defined(MSDOS))
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000136
Rich Salzf642ebc2014-08-09 08:02:20 -0400137# ifdef __DJGPP__
Matt Caswell0f113f32015-01-22 03:40:55 +0000138# include <unistd.h>
139# include <sys/stat.h>
140# include <sys/socket.h>
Richard Levitte2c25ebd2016-05-10 14:41:19 +0200141# include <sys/un.h>
Matt Caswell0f113f32015-01-22 03:40:55 +0000142# include <tcp.h>
143# include <netdb.h>
144# define _setmode setmode
145# define _O_TEXT O_TEXT
146# define _O_BINARY O_BINARY
Richard Levitte2c25ebd2016-05-10 14:41:19 +0200147# define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
148# undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
Matt Caswell0f113f32015-01-22 03:40:55 +0000149# undef DEVRANDOM
150# define DEVRANDOM "/dev/urandom\x24"
151# endif /* __DJGPP__ */
Rich Salzf642ebc2014-08-09 08:02:20 -0400152
Richard Levitte0056ef52000-03-02 07:42:48 +0000153# ifndef S_IFDIR
Matt Caswell0f113f32015-01-22 03:40:55 +0000154# define S_IFDIR _S_IFDIR
Richard Levitte0056ef52000-03-02 07:42:48 +0000155# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000156
Richard Levitte0056ef52000-03-02 07:42:48 +0000157# ifndef S_IFMT
Matt Caswell0f113f32015-01-22 03:40:55 +0000158# define S_IFMT _S_IFMT
Richard Levitte0056ef52000-03-02 07:42:48 +0000159# endif
Dr. Stephen Henson6e064241999-03-08 18:41:15 +0000160
Rich Salzf642ebc2014-08-09 08:02:20 -0400161# if !defined(WINNT) && !defined(__DJGPP__)
Matt Caswell0f113f32015-01-22 03:40:55 +0000162# define NO_SYSLOG
Richard Levitte0056ef52000-03-02 07:42:48 +0000163# endif
164# define NO_DIRENT
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000165
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000166# ifdef WINDOWS
Matt Caswell0f113f32015-01-22 03:40:55 +0000167# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
Andy Polyakove476f942005-05-21 13:19:27 +0000168 /*
Matt Caswell0f113f32015-01-22 03:40:55 +0000169 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
170 * Most notably we ought to check for availability of each specific
Andy Polyakov0ee05b72015-11-15 21:19:37 +0100171 * routine that was introduced after denoted _WIN32_WINNT with
172 * GetProcAddress(). Normally newer functions are masked with higher
173 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
174 * some module, you'd need to override _WIN32_WINNT definition in
175 * the target module in order to "reach for" prototypes, but replace
176 * calls to new functions with indirect calls. Alternatively it
177 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
178 * and check for current OS version instead.
Matt Caswell0f113f32015-01-22 03:40:55 +0000179 */
Andy Polyakov0ee05b72015-11-15 21:19:37 +0100180# define _WIN32_WINNT 0x0501
Matt Caswell0f113f32015-01-22 03:40:55 +0000181# endif
Matt Caswell2469e762016-04-20 12:43:27 +0100182# if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
Andy Polyakov61aa2132006-01-02 13:44:06 +0000183 /*
184 * Just like defining _WIN32_WINNT including winsock2.h implies
Dr. Stephen Henson8711efb2009-04-20 11:33:12 +0000185 * certain "discipline" for maintaining [broad] binary compatibility.
Andy Polyakov61aa2132006-01-02 13:44:06 +0000186 * As long as structures are invariant among Winsock versions,
187 * it's sufficient to check for specific Winsock2 API availability
188 * at run-time [DSO_global_lookup is recommended]...
189 */
Matt Caswell0f113f32015-01-22 03:40:55 +0000190# include <winsock2.h>
191# include <ws2tcpip.h>
Dr. Stephen Henson8711efb2009-04-20 11:33:12 +0000192 /* yes, they have to be #included prior to <windows.h> */
Matt Caswell0f113f32015-01-22 03:40:55 +0000193# endif
194# include <windows.h>
195# include <stdio.h>
196# include <stddef.h>
197# include <errno.h>
198# if defined(_WIN32_WCE) && !defined(EACCES)
199# define EACCES 13
200# endif
201# include <string.h>
202# ifdef _WIN64
203# define strlen(s) _strlen31(s)
Andy Polyakov1875e6d2005-07-05 11:44:45 +0000204/* cut strings to 2GB */
Andy Polyakov55c7a4c2014-09-30 21:05:33 +0200205static __inline unsigned int _strlen31(const char *str)
Matt Caswell0f113f32015-01-22 03:40:55 +0000206{
207 unsigned int len = 0;
208 while (*str && len < 0x80000000U)
209 str++, len++;
210 return len & 0x7FFFFFFF;
211}
212# endif
213# include <malloc.h>
214# if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
Andy Polyakove5272012008-12-22 13:54:12 +0000215 /* compensate for bug in VC6 ctype.h */
Matt Caswell0f113f32015-01-22 03:40:55 +0000216# undef isspace
217# undef isdigit
218# undef isalnum
219# undef isupper
220# undef isxdigit
221# endif
222# if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
223# if _MSC_VER>=1300 && _MSC_VER<1600
224# undef stdin
225# undef stdout
226# undef stderr
227FILE *__iob_func();
228# define stdin (&__iob_func()[0])
229# define stdout (&__iob_func()[1])
230# define stderr (&__iob_func()[2])
231# elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
232# undef stdin
233# undef stdout
234# undef stderr
235 /*
236 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
237 * or in other words with /MD. Declaring implicit import, i.e. with
238 * _imp_ prefix, works correctly with all compiler options, but
239 * without /MD results in LINK warning LNK4049: 'locally defined
240 * symbol "__iob" imported'.
Andy Polyakove5272012008-12-22 13:54:12 +0000241 */
Matt Caswell0f113f32015-01-22 03:40:55 +0000242extern FILE *_imp___iob;
243# define stdin (&_imp___iob[0])
244# define stdout (&_imp___iob[1])
245# define stderr (&_imp___iob[2])
Andy Polyakove5272012008-12-22 13:54:12 +0000246# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000247# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000248# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000249# include <io.h>
250# include <fcntl.h>
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000251
Richard Levitte0bf23d92002-11-15 22:37:18 +0000252# ifdef OPENSSL_SYS_WINCE
Matt Caswell0f113f32015-01-22 03:40:55 +0000253# define OPENSSL_NO_POSIX_IO
Richard Levitte0bf23d92002-11-15 22:37:18 +0000254# endif
255
Andy Polyakovbe7b4452005-12-18 19:11:37 +0000256# define EXIT(n) exit(n)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000257# define LIST_SEPARATOR_CHAR ';'
Richard Levitte0056ef52000-03-02 07:42:48 +0000258# ifndef X_OK
Matt Caswell0f113f32015-01-22 03:40:55 +0000259# define X_OK 0
Richard Levitte0056ef52000-03-02 07:42:48 +0000260# endif
261# ifndef W_OK
Matt Caswell0f113f32015-01-22 03:40:55 +0000262# define W_OK 2
Richard Levitte0056ef52000-03-02 07:42:48 +0000263# endif
264# ifndef R_OK
Matt Caswell0f113f32015-01-22 03:40:55 +0000265# define R_OK 4
Richard Levitte0056ef52000-03-02 07:42:48 +0000266# endif
Richard Levitte0bf23d92002-11-15 22:37:18 +0000267# ifdef OPENSSL_SYS_WINCE
Matt Caswell0f113f32015-01-22 03:40:55 +0000268# define DEFAULT_HOME ""
Richard Levitte0bf23d92002-11-15 22:37:18 +0000269# else
Matt Caswell0f113f32015-01-22 03:40:55 +0000270# define DEFAULT_HOME "C:"
Richard Levitte0bf23d92002-11-15 22:37:18 +0000271# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000272
Matt Caswell86d21d02015-01-09 14:06:36 +0000273/* Avoid Visual Studio 13 GetVersion deprecated problems */
Matt Caswell0f113f32015-01-22 03:40:55 +0000274# if defined(_MSC_VER) && _MSC_VER>=1800
275# define check_winnt() (1)
276# define check_win_minplat(x) (1)
277# else
278# define check_winnt() (GetVersion() < 0x80000000)
279# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
280# endif
Emilia Kasperf511b252014-08-19 13:18:07 +0200281
Matt Caswell0f113f32015-01-22 03:40:55 +0000282# else /* The non-microsoft world */
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000283
Richard Levittecf1b7d92001-02-19 16:06:34 +0000284# ifdef OPENSSL_SYS_VMS
Matt Caswell0f113f32015-01-22 03:40:55 +0000285# define VMS 1
286 /*
287 * some programs don't include stdlib, so exit() and others give implicit
288 * function warnings
289 */
290# include <stdlib.h>
291# if defined(__DECC)
292# include <unistd.h>
293# else
294# include <unixlib.h>
295# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000296# define LIST_SEPARATOR_CHAR ','
Richard Levitte0c61e292001-01-08 10:59:26 +0000297 /* We don't have any well-defined random devices on VMS, yet... */
Matt Caswell0f113f32015-01-22 03:40:55 +0000298# undef DEVRANDOM
Tim Hudson1d97c842014-12-28 12:48:40 +1000299 /*-
300 We need to do this since VMS has the following coding on status codes:
Richard Levitte511e5962000-03-17 09:25:36 +0000301
302 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
303 The important thing to know is that odd numbers are considered
Matt Caswell0f113f32015-01-22 03:40:55 +0000304 good, while even ones are considered errors.
Richard Levitte511e5962000-03-17 09:25:36 +0000305 Bits 3-15: actual status number
306 Bits 16-27: facility number. 0 is considered "unknown"
307 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
308 output the message (which, for random codes, just looks ugly)
309
310 So, what we do here is to change 0 to 1 to get the default success status,
311 and everything else is shifted up to fit into the status number field, and
Richard Levittef625d382016-01-13 18:58:15 +0100312 the status is tagged as an error, which is what is wanted here.
Richard Levittec3944a92016-01-13 17:00:22 +0100313
314 Finally, we add the VMS C facility code 0x35a000, because there are some
315 programs, such as Perl, that will reinterpret the code back to something
316 POSIXly. 'man perlvms' explains it further.
Richard Levittef625d382016-01-13 18:58:15 +0100317
Richard Levittec3944a92016-01-13 17:00:22 +0100318 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
319 codes (status type = 1). I couldn't disagree more. Fortunately, the
320 status type doesn't seem to bother Perl.
Richard Levitte511e5962000-03-17 09:25:36 +0000321 -- Richard Levitte
322 */
Richard Levittef625d382016-01-13 18:58:15 +0100323# define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
324
Matt Caswell0f113f32015-01-22 03:40:55 +0000325# define NO_SYS_PARAM_H
Richard Levittec168a022015-01-29 13:07:53 +0100326# define NO_SYS_UN_H
Richard Levitte4d8743f2003-11-28 13:10:58 +0000327
Richard Levitteb8f304f2016-06-20 07:56:32 +0200328# define DEFAULT_HOME "SYS$LOGIN:"
329
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000330# else
Bodo Möller06018c41999-06-10 08:12:20 +0000331 /* !defined VMS */
Matt Caswell0f113f32015-01-22 03:40:55 +0000332# ifdef OPENSSL_UNISTD
333# include OPENSSL_UNISTD
334# else
335# include <unistd.h>
336# endif
337# ifndef NO_SYS_TYPES_H
338# include <sys/types.h>
339# endif
340# ifdef OPENSSL_SYS_WIN32_CYGWIN
341# include <io.h>
342# include <fcntl.h>
343# endif
Ulf Möller7d7d2cb1999-05-13 11:37:32 +0000344
Matt Caswell0f113f32015-01-22 03:40:55 +0000345# define LIST_SEPARATOR_CHAR ':'
Matt Caswell0f113f32015-01-22 03:40:55 +0000346# define EXIT(n) exit(n)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000347# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000348
Matt Caswell0f113f32015-01-22 03:40:55 +0000349# endif
Ulf Möller7d7d2cb1999-05-13 11:37:32 +0000350
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000351/*************/
352
Matt Caswell0f113f32015-01-22 03:40:55 +0000353# ifdef USE_SOCKETS
David Woodhouseffbc5b52016-02-20 15:07:32 +0000354# ifdef OPENSSL_NO_SOCK
355# elif defined(WINDOWS) || defined(MSDOS)
Rich Salz37b1f8b2016-03-07 15:32:18 -0500356 /* windows world */
David Woodhouseffbc5b52016-02-20 15:07:32 +0000357# if !defined(__DJGPP__)
Matt Caswell0f113f32015-01-22 03:40:55 +0000358# if defined(_WIN32_WCE) && _WIN32_WCE<410
359# define getservbyname _masked_declaration_getservbyname
360# endif
361# if !defined(IPPROTO_IP)
Andy Polyakova6efc2d2006-10-23 07:41:05 +0000362 /* winsock[2].h was included already? */
Matt Caswell0f113f32015-01-22 03:40:55 +0000363# include <winsock.h>
364# endif
365# ifdef getservbyname
366# undef getservbyname
Andy Polyakov63d3a9c2005-11-09 17:19:38 +0000367 /* this is used to be wcecompat/include/winsock_extras.h */
Matt Caswell0f113f32015-01-22 03:40:55 +0000368struct servent *PASCAL getservbyname(const char *, const char *);
369# endif
Andy Polyakov63d3a9c2005-11-09 17:19:38 +0000370
Matt Caswell0f113f32015-01-22 03:40:55 +0000371# ifdef _WIN64
Andy Polyakov1875e6d2005-07-05 11:44:45 +0000372/*
373 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
374 * the value constitutes an index in per-process table of limited size
Andy Polyakovb13fdc42015-09-30 10:15:03 +0200375 * and not a real pointer. And we also depend on fact that all processors
376 * Windows run on happen to be two's-complement, which allows to
377 * interchange INVALID_SOCKET and -1.
Andy Polyakov1875e6d2005-07-05 11:44:45 +0000378 */
Matt Caswell0f113f32015-01-22 03:40:55 +0000379# define socket(d,t,p) ((int)socket(d,t,p))
380# define accept(s,f,l) ((int)accept(s,f,l))
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000381# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000382# else
Matt Caswell0f113f32015-01-22 03:40:55 +0000383# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000384
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000385# else
386
Matt Caswell0f113f32015-01-22 03:40:55 +0000387# ifndef NO_SYS_PARAM_H
388# include <sys/param.h>
389# endif
390# ifdef OPENSSL_SYS_VXWORKS
391# include <time.h>
392# endif
Ulf Möller7d7d2cb1999-05-13 11:37:32 +0000393
Matt Caswell0f113f32015-01-22 03:40:55 +0000394# include <netdb.h>
395# if defined(OPENSSL_SYS_VMS_NODECC)
396# include <socket.h>
397# include <in.h>
398# include <inet.h>
399# else
400# include <sys/socket.h>
401# ifndef NO_SYS_UN_H
402# ifdef OPENSSL_SYS_VXWORKS
403# include <streams/un.h>
404# else
405# include <sys/un.h>
406# endif
407# ifndef UNIX_PATH_MAX
408# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
409# endif
410# endif
411# ifdef FILIO_H
Andy Polyakovf6739c32015-11-23 14:12:17 +0100412# include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
Matt Caswell0f113f32015-01-22 03:40:55 +0000413# endif
414# include <netinet/in.h>
415# include <arpa/inet.h>
Richard Levitte28a08412016-02-02 15:54:57 +0100416# include <netinet/tcp.h>
Matt Caswell0f113f32015-01-22 03:40:55 +0000417# endif
418
419# ifdef OPENSSL_SYS_AIX
420# include <sys/select.h>
421# endif
422
423# ifdef __QNX__
424# include <sys/select.h>
425# endif
426
Andy Polyakov2f2c8052015-11-22 13:39:35 +0100427# ifndef VMS
428# include <sys/ioctl.h>
Matt Caswell0f113f32015-01-22 03:40:55 +0000429# else
Andy Polyakov2f2c8052015-11-22 13:39:35 +0100430 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
431# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
Matt Caswell0f113f32015-01-22 03:40:55 +0000432# include <sys/ioctl.h>
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000433# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000434# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000435
Matt Caswell0f113f32015-01-22 03:40:55 +0000436# ifdef VMS
437# include <unixio.h>
438# if defined(TCPIP_TYPE_SOCKETSHR)
439# include <socketshr.h>
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000440# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000441# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000442
Matt Caswell0f113f32015-01-22 03:40:55 +0000443# ifndef INVALID_SOCKET
444# define INVALID_SOCKET (-1)
445# endif /* INVALID_SOCKET */
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000446# endif
Dr. Stephen Hensona6dab872009-08-26 15:15:15 +0000447
Matt Caswell0f113f32015-01-22 03:40:55 +0000448/*
449 * Some IPv6 implementations are broken, disable them in known bad versions.
Dr. Stephen Hensona6dab872009-08-26 15:15:15 +0000450 */
451# if !defined(OPENSSL_USE_IPV6)
Matt Caswell0f113f32015-01-22 03:40:55 +0000452# if defined(AF_INET6) && !defined(NETWARE_CLIB)
453# define OPENSSL_USE_IPV6 1
454# else
455# define OPENSSL_USE_IPV6 0
456# endif
Dr. Stephen Hensona6dab872009-08-26 15:15:15 +0000457# endif
458
Richard Levitte1c3e4a32002-12-03 16:33:03 +0000459# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000460
Matt Caswell0f113f32015-01-22 03:40:55 +0000461# ifndef OPENSSL_EXIT
462# if defined(MONOLITH) && !defined(OPENSSL_C)
463# define OPENSSL_EXIT(n) return(n)
464# else
465# define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
466# endif
467# endif
Richard Levitte1c3e4a32002-12-03 16:33:03 +0000468
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000469/***********************************************/
470
Matt Caswell0f113f32015-01-22 03:40:55 +0000471# if defined(OPENSSL_SYS_WINDOWS)
Richard Levittee6fa67f2003-09-09 14:48:36 +0000472# define strcasecmp _stricmp
473# define strncasecmp _strnicmp
Richard Levittedc6b5c72016-05-25 23:35:54 +0200474# if (_MSC_VER >= 1310)
475# define open _open
476# define fdopen _fdopen
477# define close _close
Mat8d95ca32016-05-27 19:35:12 +0200478# ifndef strdup
479# define strdup _strdup
480# endif
Richard Levittedc6b5c72016-05-25 23:35:54 +0200481# define unlink _unlink
482# endif
Richard Levitte7233bea2016-05-27 10:12:58 +0200483# else
484# include <strings.h>
Matt Caswell0f113f32015-01-22 03:40:55 +0000485# endif
Richard Levitte3bfd99b2001-07-02 20:41:05 +0000486
Richard Levitte6a89a252002-10-09 13:40:48 +0000487/* vxworks */
Matt Caswell0f113f32015-01-22 03:40:55 +0000488# if defined(OPENSSL_SYS_VXWORKS)
489# include <ioLib.h>
490# include <tickLib.h>
491# include <sysLib.h>
Richard Levitte6a89a252002-10-09 13:40:48 +0000492
Matt Caswell0f113f32015-01-22 03:40:55 +0000493# define TTY_STRUCT int
Richard Levitte6a89a252002-10-09 13:40:48 +0000494
Matt Caswell0f113f32015-01-22 03:40:55 +0000495# define sleep(a) taskDelay((a) * sysClkRateGet())
Richard Levitte6a89a252002-10-09 13:40:48 +0000496
Matt Caswell0f113f32015-01-22 03:40:55 +0000497# include <vxWorks.h>
498# include <sockLib.h>
499# include <taskLib.h>
Richard Levitte6a89a252002-10-09 13:40:48 +0000500
Matt Caswell0f113f32015-01-22 03:40:55 +0000501# define getpid taskIdSelf
Richard Levitte6a89a252002-10-09 13:40:48 +0000502
Matt Caswell0f113f32015-01-22 03:40:55 +0000503/*
504 * NOTE: these are implemented by helpers in database app! if the database is
505 * not linked, we need to implement them elswhere
506 */
Richard Levitte6a89a252002-10-09 13:40:48 +0000507struct hostent *gethostbyname(const char *name);
508struct hostent *gethostbyaddr(const char *addr, int length, int type);
509struct servent *getservbyname(const char *name, const char *proto);
510
Matt Caswell0f113f32015-01-22 03:40:55 +0000511# endif
Richard Levitte6a89a252002-10-09 13:40:48 +0000512/* end vxworks */
513
Dr. Stephen Hensonb6eb9822015-05-02 18:30:00 +0100514#define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))
515
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000516#ifdef __cplusplus
517}
518#endif
519
520#endif