xref: /freebsd/crypto/openssl/e_os.h (revision 5c87c606)
174664626SKris Kennaway /* e_os.h */
274664626SKris Kennaway /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
374664626SKris Kennaway  * All rights reserved.
474664626SKris Kennaway  *
574664626SKris Kennaway  * This package is an SSL implementation written
674664626SKris Kennaway  * by Eric Young (eay@cryptsoft.com).
774664626SKris Kennaway  * The implementation was written so as to conform with Netscapes SSL.
874664626SKris Kennaway  *
974664626SKris Kennaway  * This library is free for commercial and non-commercial use as long as
1074664626SKris Kennaway  * the following conditions are aheared to.  The following conditions
1174664626SKris Kennaway  * apply to all code found in this distribution, be it the RC4, RSA,
1274664626SKris Kennaway  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1374664626SKris Kennaway  * included with this distribution is covered by the same copyright terms
1474664626SKris Kennaway  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1574664626SKris Kennaway  *
1674664626SKris Kennaway  * Copyright remains Eric Young's, and as such any Copyright notices in
1774664626SKris Kennaway  * the code are not to be removed.
1874664626SKris Kennaway  * If this package is used in a product, Eric Young should be given attribution
1974664626SKris Kennaway  * as the author of the parts of the library used.
2074664626SKris Kennaway  * This can be in the form of a textual message at program startup or
2174664626SKris Kennaway  * in documentation (online or textual) provided with the package.
2274664626SKris Kennaway  *
2374664626SKris Kennaway  * Redistribution and use in source and binary forms, with or without
2474664626SKris Kennaway  * modification, are permitted provided that the following conditions
2574664626SKris Kennaway  * are met:
2674664626SKris Kennaway  * 1. Redistributions of source code must retain the copyright
2774664626SKris Kennaway  *    notice, this list of conditions and the following disclaimer.
2874664626SKris Kennaway  * 2. Redistributions in binary form must reproduce the above copyright
2974664626SKris Kennaway  *    notice, this list of conditions and the following disclaimer in the
3074664626SKris Kennaway  *    documentation and/or other materials provided with the distribution.
3174664626SKris Kennaway  * 3. All advertising materials mentioning features or use of this software
3274664626SKris Kennaway  *    must display the following acknowledgement:
3374664626SKris Kennaway  *    "This product includes cryptographic software written by
3474664626SKris Kennaway  *     Eric Young (eay@cryptsoft.com)"
3574664626SKris Kennaway  *    The word 'cryptographic' can be left out if the rouines from the library
3674664626SKris Kennaway  *    being used are not cryptographic related :-).
3774664626SKris Kennaway  * 4. If you include any Windows specific code (or a derivative thereof) from
3874664626SKris Kennaway  *    the apps directory (application code) you must include an acknowledgement:
3974664626SKris Kennaway  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4074664626SKris Kennaway  *
4174664626SKris Kennaway  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4274664626SKris Kennaway  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4374664626SKris Kennaway  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4474664626SKris Kennaway  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4574664626SKris Kennaway  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4674664626SKris Kennaway  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4774664626SKris Kennaway  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4874664626SKris Kennaway  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4974664626SKris Kennaway  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5074664626SKris Kennaway  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5174664626SKris Kennaway  * SUCH DAMAGE.
5274664626SKris Kennaway  *
5374664626SKris Kennaway  * The licence and distribution terms for any publically available version or
5474664626SKris Kennaway  * derivative of this code cannot be changed.  i.e. this code cannot simply be
5574664626SKris Kennaway  * copied and put under another distribution licence
5674664626SKris Kennaway  * [including the GNU Public Licence.]
5774664626SKris Kennaway  */
5874664626SKris Kennaway 
5974664626SKris Kennaway #ifndef HEADER_E_OS_H
6074664626SKris Kennaway #define HEADER_E_OS_H
6174664626SKris Kennaway 
6274664626SKris Kennaway #include <openssl/opensslconf.h>
6374664626SKris Kennaway 
6474664626SKris Kennaway #include <openssl/e_os2.h>
6574664626SKris Kennaway /* <openssl/e_os2.h> contains what we can justify to make visible
6674664626SKris Kennaway  * to the outside; this file e_os.h is not part of the exported
6774664626SKris Kennaway  * interface. */
6874664626SKris Kennaway 
6974664626SKris Kennaway #ifdef  __cplusplus
7074664626SKris Kennaway extern "C" {
7174664626SKris Kennaway #endif
7274664626SKris Kennaway 
7374664626SKris Kennaway /* Used to checking reference counts, most while doing perl5 stuff :-) */
7474664626SKris Kennaway #ifdef REF_PRINT
7574664626SKris Kennaway #undef REF_PRINT
7674664626SKris Kennaway #define REF_PRINT(a,b)	fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a)
7774664626SKris Kennaway #endif
7874664626SKris Kennaway 
7974664626SKris Kennaway #ifndef DEVRANDOM
805c87c606SMark Murray /* set this to a comma-separated list of 'random' device files to try out.
815c87c606SMark Murray  * My default, we will try to read at least one of these files */
825c87c606SMark Murray #define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
835c87c606SMark Murray #endif
845c87c606SMark Murray #ifndef DEVRANDOM_EGD
855c87c606SMark Murray /* set this to a comma-seperated list of 'egd' sockets to try out. These
865c87c606SMark Murray  * sockets will be tried in the order listed in case accessing the device files
875c87c606SMark Murray  * listed in DEVRANDOM did not return enough entropy. */
885c87c606SMark Murray #define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
8974664626SKris Kennaway #endif
9074664626SKris Kennaway 
915c87c606SMark Murray #if defined(OPENSSL_SYS_VXWORKS)
92c1803d78SJacques Vidrine #  define NO_SYS_PARAM_H
93c1803d78SJacques Vidrine #  define NO_CHMOD
94c1803d78SJacques Vidrine #  define NO_SYSLOG
95c1803d78SJacques Vidrine #endif
96c1803d78SJacques Vidrine 
975c87c606SMark Murray #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC)
98f579bf8eSKris Kennaway # if macintosh==1
99f579bf8eSKris Kennaway #  ifndef MAC_OS_GUSI_SOURCE
100f579bf8eSKris Kennaway #    define MAC_OS_pre_X
101f579bf8eSKris Kennaway #    define NO_SYS_TYPES_H
102ddd58736SKris Kennaway      typedef long ssize_t;
103f579bf8eSKris Kennaway #  endif
104f579bf8eSKris Kennaway #  define NO_SYS_PARAM_H
105f579bf8eSKris Kennaway #  define NO_CHMOD
106f579bf8eSKris Kennaway #  define NO_SYSLOG
107f579bf8eSKris Kennaway #  undef  DEVRANDOM
108f579bf8eSKris Kennaway #  define GETPID_IS_MEANINGLESS
109f579bf8eSKris Kennaway # endif
110f579bf8eSKris Kennaway #endif
111f579bf8eSKris Kennaway 
11274664626SKris Kennaway /********************************************************************
11374664626SKris Kennaway  The Microsoft section
11474664626SKris Kennaway  ********************************************************************/
11574664626SKris Kennaway /* The following is used becaue of the small stack in some
11674664626SKris Kennaway  * Microsoft operating systems */
1175c87c606SMark Murray #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYSNAME_WIN32)
11874664626SKris Kennaway #  define MS_STATIC	static
11974664626SKris Kennaway #else
12074664626SKris Kennaway #  define MS_STATIC
12174664626SKris Kennaway #endif
12274664626SKris Kennaway 
1235c87c606SMark Murray #if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
124f579bf8eSKris Kennaway #  define WIN32
125f579bf8eSKris Kennaway #endif
1265c87c606SMark Murray #if defined(OPENSSL_SYS_WIN16) && !defined(WIN16)
1275c87c606SMark Murray #  define WIN16
1285c87c606SMark Murray #endif
1295c87c606SMark Murray #if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
13074664626SKris Kennaway #  define WINDOWS
13174664626SKris Kennaway #endif
1325c87c606SMark Murray #if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
13374664626SKris Kennaway #  define MSDOS
13474664626SKris Kennaway #endif
13574664626SKris Kennaway 
136f579bf8eSKris Kennaway #if defined(MSDOS) && !defined(GETPID_IS_MEANINGLESS)
137f579bf8eSKris Kennaway #  define GETPID_IS_MEANINGLESS
138f579bf8eSKris Kennaway #endif
139f579bf8eSKris Kennaway 
14074664626SKris Kennaway #ifdef WIN32
14174664626SKris Kennaway #define get_last_sys_error()	GetLastError()
14274664626SKris Kennaway #define clear_sys_error()	SetLastError(0)
14374664626SKris Kennaway #if !defined(WINNT)
14474664626SKris Kennaway #define WIN_CONSOLE_BUG
14574664626SKris Kennaway #endif
14674664626SKris Kennaway #else
14774664626SKris Kennaway #define get_last_sys_error()	errno
14874664626SKris Kennaway #define clear_sys_error()	errno=0
14974664626SKris Kennaway #endif
15074664626SKris Kennaway 
1515c87c606SMark Murray #if defined(WINDOWS)
15274664626SKris Kennaway #define get_last_socket_error()	WSAGetLastError()
15374664626SKris Kennaway #define clear_socket_error()	WSASetLastError(0)
15474664626SKris Kennaway #define readsocket(s,b,n)	recv((s),(b),(n),0)
15574664626SKris Kennaway #define writesocket(s,b,n)	send((s),(b),(n),0)
15674664626SKris Kennaway #define EADDRINUSE		WSAEADDRINUSE
1575c87c606SMark Murray #elif defined(__DJGPP__)
1585c87c606SMark Murray #define WATT32
1595c87c606SMark Murray #define get_last_socket_error()	errno
1605c87c606SMark Murray #define clear_socket_error()	errno=0
1615c87c606SMark Murray #define closesocket(s)		close_s(s)
1625c87c606SMark Murray #define readsocket(s,b,n)	read_s(s,b,n)
1635c87c606SMark Murray #define writesocket(s,b,n)	send(s,b,n,0)
164f579bf8eSKris Kennaway #elif defined(MAC_OS_pre_X)
165f579bf8eSKris Kennaway #define get_last_socket_error()	errno
166f579bf8eSKris Kennaway #define clear_socket_error()	errno=0
167f579bf8eSKris Kennaway #define closesocket(s)		MacSocket_close(s)
168f579bf8eSKris Kennaway #define readsocket(s,b,n)	MacSocket_recv((s),(b),(n),true)
169f579bf8eSKris Kennaway #define writesocket(s,b,n)	MacSocket_send((s),(b),(n))
1705c87c606SMark Murray #elif defined(OPENSSL_SYS_VMS)
171c1803d78SJacques Vidrine #define get_last_socket_error() errno
172c1803d78SJacques Vidrine #define clear_socket_error()    errno=0
173c1803d78SJacques Vidrine #define ioctlsocket(a,b,c)      ioctl(a,b,c)
174c1803d78SJacques Vidrine #define closesocket(s)          close(s)
175c1803d78SJacques Vidrine #define readsocket(s,b,n)       recv((s),(b),(n),0)
176c1803d78SJacques Vidrine #define writesocket(s,b,n)      send((s),(b),(n),0)
17774664626SKris Kennaway #else
17874664626SKris Kennaway #define get_last_socket_error()	errno
17974664626SKris Kennaway #define clear_socket_error()	errno=0
18074664626SKris Kennaway #define ioctlsocket(a,b,c)	ioctl(a,b,c)
18174664626SKris Kennaway #define closesocket(s)		close(s)
18274664626SKris Kennaway #define readsocket(s,b,n)	read((s),(b),(n))
18374664626SKris Kennaway #define writesocket(s,b,n)	write((s),(b),(n))
18474664626SKris Kennaway #endif
18574664626SKris Kennaway 
18674664626SKris Kennaway #ifdef WIN16
1875c87c606SMark Murray #  define OPENSSL_NO_FP_API
18874664626SKris Kennaway #  define MS_CALLBACK	_far _loadds
18974664626SKris Kennaway #  define MS_FAR	_far
19074664626SKris Kennaway #else
19174664626SKris Kennaway #  define MS_CALLBACK
19274664626SKris Kennaway #  define MS_FAR
19374664626SKris Kennaway #endif
19474664626SKris Kennaway 
1955c87c606SMark Murray #ifdef OPENSSL_NO_STDIO
1965c87c606SMark Murray #  define OPENSSL_NO_FP_API
19774664626SKris Kennaway #endif
19874664626SKris Kennaway 
1995c87c606SMark Murray #if (defined(WINDOWS) || defined(MSDOS))
2005c87c606SMark Murray 
2015c87c606SMark Murray #  ifdef __DJGPP__
2025c87c606SMark Murray #    include <unistd.h>
2035c87c606SMark Murray #    include <sys/stat.h>
2045c87c606SMark Murray #    include <sys/socket.h>
2055c87c606SMark Murray #    include <tcp.h>
2065c87c606SMark Murray #    include <netdb.h>
2075c87c606SMark Murray #    define _setmode setmode
2085c87c606SMark Murray #    define _O_TEXT O_TEXT
2095c87c606SMark Murray #    define _O_BINARY O_BINARY
2105c87c606SMark Murray #  endif /* __DJGPP__ */
21174664626SKris Kennaway 
21274664626SKris Kennaway #  ifndef S_IFDIR
21374664626SKris Kennaway #    define S_IFDIR	_S_IFDIR
21474664626SKris Kennaway #  endif
21574664626SKris Kennaway 
21674664626SKris Kennaway #  ifndef S_IFMT
21774664626SKris Kennaway #    define S_IFMT	_S_IFMT
218f579bf8eSKris Kennaway #  endif
21974664626SKris Kennaway 
2205c87c606SMark Murray #  if !defined(WINNT) && !defined(__DJGPP__)
22174664626SKris Kennaway #    define NO_SYSLOG
22274664626SKris Kennaway #  endif
22374664626SKris Kennaway #  define NO_DIRENT
22474664626SKris Kennaway 
22574664626SKris Kennaway #  ifdef WINDOWS
22674664626SKris Kennaway #    include <windows.h>
22774664626SKris Kennaway #    include <stddef.h>
22874664626SKris Kennaway #    include <errno.h>
22974664626SKris Kennaway #    include <string.h>
23074664626SKris Kennaway #    include <malloc.h>
23174664626SKris Kennaway #  endif
23274664626SKris Kennaway #  include <io.h>
23374664626SKris Kennaway #  include <fcntl.h>
23474664626SKris Kennaway 
2355c87c606SMark Murray #  ifdef OPENSSL_SYS_WINCE
2365c87c606SMark Murray #    include <winsock_extras.h>
2375c87c606SMark Murray #  endif
2385c87c606SMark Murray 
239f579bf8eSKris Kennaway #  define ssize_t long
240f579bf8eSKris Kennaway 
24174664626SKris Kennaway #  if defined (__BORLANDC__)
24274664626SKris Kennaway #    define _setmode setmode
24374664626SKris Kennaway #    define _O_TEXT O_TEXT
24474664626SKris Kennaway #    define _O_BINARY O_BINARY
24574664626SKris Kennaway #    define _int64 __int64
246f579bf8eSKris Kennaway #    define _kbhit kbhit
24774664626SKris Kennaway #  endif
24874664626SKris Kennaway 
2495c87c606SMark Murray #  if defined(WIN16) && defined(SSLEAY) && defined(_WINEXITNOPERSIST)
2505c87c606SMark Murray #    define EXIT(n) _wsetexit(_WINEXITNOPERSIST)
2515c87c606SMark Murray #    define OPENSSL_EXIT(n) do { if (n == 0) EXIT(n); return(n); } while(0)
25274664626SKris Kennaway #  else
2535c87c606SMark Murray #    define EXIT(n) return(n)
25474664626SKris Kennaway #  endif
25574664626SKris Kennaway #  define LIST_SEPARATOR_CHAR ';'
25674664626SKris Kennaway #  ifndef X_OK
25774664626SKris Kennaway #    define X_OK	0
25874664626SKris Kennaway #  endif
25974664626SKris Kennaway #  ifndef W_OK
26074664626SKris Kennaway #    define W_OK	2
26174664626SKris Kennaway #  endif
26274664626SKris Kennaway #  ifndef R_OK
26374664626SKris Kennaway #    define R_OK	4
26474664626SKris Kennaway #  endif
26574664626SKris Kennaway #  define OPENSSL_CONF	"openssl.cnf"
26674664626SKris Kennaway #  define SSLEAY_CONF	OPENSSL_CONF
26774664626SKris Kennaway #  define NUL_DEV	"nul"
26874664626SKris Kennaway #  define RFILE		".rnd"
2695c87c606SMark Murray #  ifdef OPENSSL_SYS_WINCE
2705c87c606SMark Murray #    define DEFAULT_HOME  ""
2715c87c606SMark Murray #  else
27226d191b4SKris Kennaway #    define DEFAULT_HOME  "C:"
2735c87c606SMark Murray #  endif
27474664626SKris Kennaway 
27574664626SKris Kennaway #else /* The non-microsoft world world */
27674664626SKris Kennaway 
2775c87c606SMark Murray #  ifdef OPENSSL_SYS_VMS
27874664626SKris Kennaway #    define VMS 1
27974664626SKris Kennaway   /* some programs don't include stdlib, so exit() and others give implicit
28074664626SKris Kennaway      function warnings */
28174664626SKris Kennaway #    include <stdlib.h>
28274664626SKris Kennaway #    if defined(__DECC)
28374664626SKris Kennaway #      include <unistd.h>
28474664626SKris Kennaway #    else
28574664626SKris Kennaway #      include <unixlib.h>
28674664626SKris Kennaway #    endif
28774664626SKris Kennaway #    define OPENSSL_CONF	"openssl.cnf"
28874664626SKris Kennaway #    define SSLEAY_CONF		OPENSSL_CONF
28974664626SKris Kennaway #    define RFILE		".rnd"
29074664626SKris Kennaway #    define LIST_SEPARATOR_CHAR ','
29174664626SKris Kennaway #    define NUL_DEV		"NLA0:"
2925c87c606SMark Murray   /* We don't have any well-defined random devices on VMS, yet... */
2935c87c606SMark Murray #    undef DEVRANDOM
294f579bf8eSKris Kennaway   /* We need to do this since VMS has the following coding on status codes:
295f579bf8eSKris Kennaway 
296f579bf8eSKris Kennaway      Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
297f579bf8eSKris Kennaway                The important thing to know is that odd numbers are considered
298f579bf8eSKris Kennaway 	       good, while even ones are considered errors.
299f579bf8eSKris Kennaway      Bits 3-15: actual status number
300f579bf8eSKris Kennaway      Bits 16-27: facility number.  0 is considered "unknown"
301f579bf8eSKris Kennaway      Bits 28-31: control bits.  If bit 28 is set, the shell won't try to
302f579bf8eSKris Kennaway                  output the message (which, for random codes, just looks ugly)
303f579bf8eSKris Kennaway 
304f579bf8eSKris Kennaway      So, what we do here is to change 0 to 1 to get the default success status,
305f579bf8eSKris Kennaway      and everything else is shifted up to fit into the status number field, and
306f579bf8eSKris Kennaway      the status is tagged as an error, which I believe is what is wanted here.
307f579bf8eSKris Kennaway      -- Richard Levitte
308f579bf8eSKris Kennaway   */
30974664626SKris Kennaway #    define EXIT(n)		do { int __VMS_EXIT = n; \
310f579bf8eSKris Kennaway                                      if (__VMS_EXIT == 0) \
311f579bf8eSKris Kennaway 				       __VMS_EXIT = 1; \
312f579bf8eSKris Kennaway 				     else \
313f579bf8eSKris Kennaway 				       __VMS_EXIT = (n << 3) | 2; \
31474664626SKris Kennaway                                      __VMS_EXIT |= 0x10000000; \
3155c87c606SMark Murray 				     exit(__VMS_EXIT); } while(0)
316f579bf8eSKris Kennaway #    define NO_SYS_PARAM_H
31774664626SKris Kennaway #  else
31874664626SKris Kennaway      /* !defined VMS */
3195c87c606SMark Murray #    ifdef OPENSSL_SYS_MPE
320ddd58736SKris Kennaway #      define NO_SYS_PARAM_H
321ddd58736SKris Kennaway #    endif
322f579bf8eSKris Kennaway #    ifdef OPENSSL_UNISTD
32374664626SKris Kennaway #      include OPENSSL_UNISTD
324f579bf8eSKris Kennaway #    else
325f579bf8eSKris Kennaway #      include <unistd.h>
326f579bf8eSKris Kennaway #    endif
327f579bf8eSKris Kennaway #    ifndef NO_SYS_TYPES_H
328f579bf8eSKris Kennaway #      include <sys/types.h>
329f579bf8eSKris Kennaway #    endif
3305c87c606SMark Murray #    if defined(NeXT) || defined(OPENSSL_SYS_NEWS4)
331f579bf8eSKris Kennaway #      define pid_t int /* pid_t is missing on NEXTSTEP/OPENSTEP
332f579bf8eSKris Kennaway                          * (unless when compiling with -D_POSIX_SOURCE,
333f579bf8eSKris Kennaway                          * which doesn't work for us) */
334f579bf8eSKris Kennaway #      define ssize_t int /* ditto */
335f579bf8eSKris Kennaway #    endif
3365c87c606SMark Murray #    ifdef OPENSSL_SYS_NEWS4 /* setvbuf is missing on mips-sony-bsd */
337ddd58736SKris Kennaway #      define setvbuf(a, b, c, d) setbuffer((a), (b), (d))
338ddd58736SKris Kennaway        typedef unsigned long clock_t;
339ddd58736SKris Kennaway #    endif
34074664626SKris Kennaway 
34174664626SKris Kennaway #    define OPENSSL_CONF	"openssl.cnf"
34274664626SKris Kennaway #    define SSLEAY_CONF		OPENSSL_CONF
34374664626SKris Kennaway #    define RFILE		".rnd"
34474664626SKris Kennaway #    define LIST_SEPARATOR_CHAR ':'
34574664626SKris Kennaway #    define NUL_DEV		"/dev/null"
3465c87c606SMark Murray #    define EXIT(n)		exit(n)
34774664626SKris Kennaway #  endif
34874664626SKris Kennaway 
34974664626SKris Kennaway #  define SSLeay_getpid()	getpid()
35074664626SKris Kennaway 
35174664626SKris Kennaway #endif
35274664626SKris Kennaway 
35374664626SKris Kennaway 
35474664626SKris Kennaway /*************/
35574664626SKris Kennaway 
35674664626SKris Kennaway #ifdef USE_SOCKETS
35774664626SKris Kennaway #  if defined(WINDOWS) || defined(MSDOS)
35874664626SKris Kennaway       /* windows world */
35974664626SKris Kennaway 
3605c87c606SMark Murray #    ifdef OPENSSL_NO_SOCK
36174664626SKris Kennaway #      define SSLeay_Write(a,b,c)	(-1)
36274664626SKris Kennaway #      define SSLeay_Read(a,b,c)	(-1)
36374664626SKris Kennaway #      define SHUTDOWN(fd)		close(fd)
36474664626SKris Kennaway #      define SHUTDOWN2(fd)		close(fd)
3655c87c606SMark Murray #    elif !defined(__DJGPP__)
36674664626SKris Kennaway #      include <winsock.h>
36774664626SKris Kennaway extern HINSTANCE _hInstance;
36874664626SKris Kennaway #      define SSLeay_Write(a,b,c)	send((a),(b),(c),0)
36974664626SKris Kennaway #      define SSLeay_Read(a,b,c)	recv((a),(b),(c),0)
37074664626SKris Kennaway #      define SHUTDOWN(fd)		{ shutdown((fd),0); closesocket(fd); }
37174664626SKris Kennaway #      define SHUTDOWN2(fd)		{ shutdown((fd),2); closesocket(fd); }
3725c87c606SMark Murray #    else
3735c87c606SMark Murray #      define SSLeay_Write(a,b,c)	write_s(a,b,c,0)
3745c87c606SMark Murray #      define SSLeay_Read(a,b,c)	read_s(a,b,c)
3755c87c606SMark Murray #      define SHUTDOWN(fd)		close_s(fd)
3765c87c606SMark Murray #      define SHUTDOWN2(fd)		close_s(fd)
37774664626SKris Kennaway #    endif
37874664626SKris Kennaway 
379f579bf8eSKris Kennaway #  elif defined(MAC_OS_pre_X)
380f579bf8eSKris Kennaway 
381f579bf8eSKris Kennaway #    include "MacSocket.h"
382f579bf8eSKris Kennaway #    define SSLeay_Write(a,b,c)		MacSocket_send((a),(b),(c))
383f579bf8eSKris Kennaway #    define SSLeay_Read(a,b,c)		MacSocket_recv((a),(b),(c),true)
384f579bf8eSKris Kennaway #    define SHUTDOWN(fd)		MacSocket_close(fd)
385f579bf8eSKris Kennaway #    define SHUTDOWN2(fd)		MacSocket_close(fd)
38674664626SKris Kennaway 
38774664626SKris Kennaway #  else
38874664626SKris Kennaway 
389f579bf8eSKris Kennaway #    ifndef NO_SYS_PARAM_H
39074664626SKris Kennaway #      include <sys/param.h>
39174664626SKris Kennaway #    endif
3925c87c606SMark Murray #    ifdef OPENSSL_SYS_VXWORKS
393c1803d78SJacques Vidrine #      include <time.h>
3945c87c606SMark Murray #    elif !defined(OPENSSL_SYS_MPE)
39574664626SKris Kennaway #      include <sys/time.h> /* Needed under linux for FD_XXX */
396ddd58736SKris Kennaway #    endif
39774664626SKris Kennaway 
39874664626SKris Kennaway #    include <netdb.h>
3995c87c606SMark Murray #    if defined(OPENSSL_SYS_VMS_NODECC)
40074664626SKris Kennaway #      include <socket.h>
40174664626SKris Kennaway #      include <in.h>
402de7cdddaSKris Kennaway #      include <inet.h>
40374664626SKris Kennaway #    else
40474664626SKris Kennaway #      include <sys/socket.h>
40574664626SKris Kennaway #      ifdef FILIO_H
40674664626SKris Kennaway #        include <sys/filio.h> /* Added for FIONBIO under unixware */
40774664626SKris Kennaway #      endif
40874664626SKris Kennaway #      include <netinet/in.h>
409de7cdddaSKris Kennaway #      include <arpa/inet.h>
41074664626SKris Kennaway #    endif
41174664626SKris Kennaway 
41274664626SKris Kennaway #    if defined(NeXT) || defined(_NEXT_SOURCE)
41374664626SKris Kennaway #      include <sys/fcntl.h>
41474664626SKris Kennaway #      include <sys/types.h>
41574664626SKris Kennaway #    endif
41674664626SKris Kennaway 
4175c87c606SMark Murray #    ifdef OPENSSL_SYS_AIX
41874664626SKris Kennaway #      include <sys/select.h>
41974664626SKris Kennaway #    endif
42074664626SKris Kennaway 
421ddd58736SKris Kennaway #    ifdef __QNX__
422ddd58736SKris Kennaway #      include <sys/select.h>
423ddd58736SKris Kennaway #    endif
424ddd58736SKris Kennaway 
42574664626SKris Kennaway #    if defined(sun)
42674664626SKris Kennaway #      include <sys/filio.h>
42774664626SKris Kennaway #    else
42874664626SKris Kennaway #      ifndef VMS
42974664626SKris Kennaway #        include <sys/ioctl.h>
43074664626SKris Kennaway #      else
43174664626SKris Kennaway 	 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
43274664626SKris Kennaway #        if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
43374664626SKris Kennaway #          include <sys/ioctl.h>
43474664626SKris Kennaway #        endif
43574664626SKris Kennaway #      endif
43674664626SKris Kennaway #    endif
43774664626SKris Kennaway 
43874664626SKris Kennaway #    ifdef VMS
43974664626SKris Kennaway #      include <unixio.h>
44074664626SKris Kennaway #      if defined(TCPIP_TYPE_SOCKETSHR)
44174664626SKris Kennaway #        include <socketshr.h>
44274664626SKris Kennaway #      endif
44374664626SKris Kennaway #    endif
44474664626SKris Kennaway 
44574664626SKris Kennaway #    define SSLeay_Read(a,b,c)     read((a),(b),(c))
44674664626SKris Kennaway #    define SSLeay_Write(a,b,c)    write((a),(b),(c))
447f579bf8eSKris Kennaway #    define SHUTDOWN(fd)    { shutdown((fd),0); closesocket((fd)); }
448f579bf8eSKris Kennaway #    define SHUTDOWN2(fd)   { shutdown((fd),2); closesocket((fd)); }
4495c87c606SMark Murray #    ifndef INVALID_SOCKET
45074664626SKris Kennaway #    define INVALID_SOCKET	(-1)
4515c87c606SMark Murray #    endif /* INVALID_SOCKET */
45274664626SKris Kennaway #  endif
45374664626SKris Kennaway #endif
45474664626SKris Kennaway 
455f579bf8eSKris Kennaway #if defined(__ultrix)
456f579bf8eSKris Kennaway #  ifndef ssize_t
457f579bf8eSKris Kennaway #    define ssize_t int
458f579bf8eSKris Kennaway #  endif
459f579bf8eSKris Kennaway #endif
460f579bf8eSKris Kennaway 
461ddd58736SKris Kennaway #if defined(sun) && !defined(__svr4__) && !defined(__SVR4)
462a21b1b38SKris Kennaway   /* include headers first, so our defines don't break it */
463a21b1b38SKris Kennaway #include <stdlib.h>
464a21b1b38SKris Kennaway #include <string.h>
465ddd58736SKris Kennaway   /* bcopy can handle overlapping moves according to SunOS 4.1.4 manpage */
466ddd58736SKris Kennaway # define memmove(s1,s2,n) bcopy((s2),(s1),(n))
467ddd58736SKris Kennaway # define strtoul(s,e,b) ((unsigned long int)strtol((s),(e),(b)))
468ddd58736SKris Kennaway extern char *sys_errlist[]; extern int sys_nerr;
469ddd58736SKris Kennaway # define strerror(errnum) \
470ddd58736SKris Kennaway 	(((errnum)<0 || (errnum)>=sys_nerr) ? NULL : sys_errlist[errnum])
471ddd58736SKris Kennaway #endif
472ddd58736SKris Kennaway 
4735c87c606SMark Murray #ifndef OPENSSL_EXIT
4745c87c606SMark Murray # if defined(MONOLITH) && !defined(OPENSSL_C)
4755c87c606SMark Murray #  define OPENSSL_EXIT(n) return(n)
4765c87c606SMark Murray # else
4775c87c606SMark Murray #  define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
4785c87c606SMark Murray # endif
4795c87c606SMark Murray #endif
4805c87c606SMark Murray 
48174664626SKris Kennaway /***********************************************/
48274664626SKris Kennaway 
48374664626SKris Kennaway /* do we need to do this for getenv.
48474664626SKris Kennaway  * Just define getenv for use under windows */
48574664626SKris Kennaway 
48674664626SKris Kennaway #ifdef WIN16
48774664626SKris Kennaway /* How to do this needs to be thought out a bit more.... */
48874664626SKris Kennaway /*char *GETENV(char *);
48974664626SKris Kennaway #define Getenv	GETENV*/
49074664626SKris Kennaway #define Getenv	getenv
49174664626SKris Kennaway #else
49274664626SKris Kennaway #define Getenv getenv
49374664626SKris Kennaway #endif
49474664626SKris Kennaway 
49574664626SKris Kennaway #define DG_GCC_BUG	/* gcc < 2.6.3 on DGUX */
49674664626SKris Kennaway 
49774664626SKris Kennaway #ifdef sgi
49874664626SKris Kennaway #define IRIX_CC_BUG	/* all version of IRIX I've tested (4.* 5.*) */
49974664626SKris Kennaway #endif
5005c87c606SMark Murray #ifdef OPENSSL_SYS_SNI
50174664626SKris Kennaway #define IRIX_CC_BUG	/* CDS++ up to V2.0Bsomething suffered from the same bug.*/
50274664626SKris Kennaway #endif
50374664626SKris Kennaway 
5045c87c606SMark Murray #if defined(OPENSSL_SYS_OS2) && defined(__EMX__)
5055c87c606SMark Murray # include <io.h>
5065c87c606SMark Murray # include <fcntl.h>
5075c87c606SMark Murray # define NO_SYSLOG
5085c87c606SMark Murray # define strcasecmp stricmp
50974664626SKris Kennaway #endif
5105c87c606SMark Murray 
5115c87c606SMark Murray /* vxworks */
5125c87c606SMark Murray #if defined(OPENSSL_SYS_VXWORKS)
5135c87c606SMark Murray #include <ioLib.h>
5145c87c606SMark Murray #include <tickLib.h>
5155c87c606SMark Murray #include <sysLib.h>
5165c87c606SMark Murray 
5175c87c606SMark Murray #define TTY_STRUCT int
5185c87c606SMark Murray 
5195c87c606SMark Murray #define sleep(a) taskDelay((a) * sysClkRateGet())
5205c87c606SMark Murray #if defined(ioctlsocket)
5215c87c606SMark Murray #undef ioctlsocket
52274664626SKris Kennaway #endif
5235c87c606SMark Murray #define ioctlsocket(a,b,c) ioctl((a),(b),*(c))
5245c87c606SMark Murray 
5255c87c606SMark Murray #include <vxWorks.h>
5265c87c606SMark Murray #include <sockLib.h>
5275c87c606SMark Murray #include <taskLib.h>
5285c87c606SMark Murray 
5295c87c606SMark Murray #define getpid taskIdSelf
5305c87c606SMark Murray 
5315c87c606SMark Murray /* NOTE: these are implemented by helpers in database app!
5325c87c606SMark Murray  * if the database is not linked, we need to implement them
5335c87c606SMark Murray  * elswhere */
5345c87c606SMark Murray struct hostent *gethostbyname(const char *name);
5355c87c606SMark Murray struct hostent *gethostbyaddr(const char *addr, int length, int type);
5365c87c606SMark Murray struct servent *getservbyname(const char *name, const char *proto);
5375c87c606SMark Murray 
5385c87c606SMark Murray #endif
5395c87c606SMark Murray /* end vxworks */
54074664626SKris Kennaway 
54174664626SKris Kennaway #ifdef  __cplusplus
54274664626SKris Kennaway }
54374664626SKris Kennaway #endif
54474664626SKris Kennaway 
54574664626SKris Kennaway #endif
54674664626SKris Kennaway 
547