155714Skris/* e_os.h */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8280304Sjkim * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15280304Sjkim * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22280304Sjkim * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37280304Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40280304Sjkim * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52280304Sjkim * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 5955714Skris#ifndef HEADER_E_OS_H 60280304Sjkim# define HEADER_E_OS_H 6155714Skris 62280304Sjkim# include <openssl/opensslconf.h> 6355714Skris 64280304Sjkim# include <openssl/e_os2.h> 65280304Sjkim/* 66280304Sjkim * <openssl/e_os2.h> contains what we can justify to make visible to the 67280304Sjkim * outside; this file e_os.h is not part of the exported interface. 68280304Sjkim */ 6955714Skris 7055714Skris#ifdef __cplusplus 7155714Skrisextern "C" { 7255714Skris#endif 7355714Skris 7455714Skris/* Used to checking reference counts, most while doing perl5 stuff :-) */ 75280304Sjkim# ifdef REF_PRINT 76280304Sjkim# undef REF_PRINT 77280304Sjkim# define REF_PRINT(a,b) fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a) 78280304Sjkim# endif 7955714Skris 80280304Sjkim# ifndef DEVRANDOM 81280304Sjkim/* 82280304Sjkim * set this to a comma-separated list of 'random' device files to try out. My 83280304Sjkim * default, we will try to read at least one of these files 84280304Sjkim */ 85280304Sjkim# define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom" 86280304Sjkim# endif 87280304Sjkim# ifndef DEVRANDOM_EGD 88280304Sjkim/* 89280304Sjkim * set this to a comma-seperated list of 'egd' sockets to try out. These 90280304Sjkim * sockets will be tried in the order listed in case accessing the device 91280304Sjkim * files listed in DEVRANDOM did not return enough entropy. 92280304Sjkim */ 93280304Sjkim# define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy" 94280304Sjkim# endif 9555714Skris 96280304Sjkim# if defined(OPENSSL_SYS_VXWORKS) 97100928Snectar# define NO_SYS_PARAM_H 98100928Snectar# define NO_CHMOD 99100928Snectar# define NO_SYSLOG 100280304Sjkim# endif 101280304Sjkim 102280304Sjkim# if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 103280304Sjkim# if macintosh==1 104280304Sjkim# ifndef MAC_OS_GUSI_SOURCE 10559191Skris# define MAC_OS_pre_X 10659191Skris# define NO_SYS_TYPES_H 107280304Sjkim# endif 108280304Sjkim# define NO_SYS_PARAM_H 109280304Sjkim# define NO_CHMOD 110280304Sjkim# define NO_SYSLOG 111280304Sjkim# undef DEVRANDOM 112280304Sjkim# define GETPID_IS_MEANINGLESS 11359191Skris# endif 11459191Skris# endif 11559191Skris 11655714Skris/******************************************************************** 11755714Skris The Microsoft section 11855714Skris ********************************************************************/ 119280304Sjkim/* 120280304Sjkim * The following is used because of the small stack in some Microsoft 121280304Sjkim * operating systems 122280304Sjkim */ 123280304Sjkim# if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYSNAME_WIN32) 124280304Sjkim# define MS_STATIC static 125280304Sjkim# else 12655714Skris# define MS_STATIC 127280304Sjkim# endif 12855714Skris 129280304Sjkim# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32) 13059191Skris# define WIN32 131280304Sjkim# endif 132280304Sjkim# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS) 133109998Smarkm# define WINDOWS 134280304Sjkim# endif 135280304Sjkim# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS) 136109998Smarkm# define MSDOS 137280304Sjkim# endif 13855714Skris 139280304Sjkim# if defined(MSDOS) && !defined(GETPID_IS_MEANINGLESS) 14059191Skris# define GETPID_IS_MEANINGLESS 141280304Sjkim# endif 14259191Skris 143280304Sjkim# ifdef WIN32 144280304Sjkim# define get_last_sys_error() GetLastError() 145280304Sjkim# define clear_sys_error() SetLastError(0) 146280304Sjkim# if !defined(WINNT) 147280304Sjkim# define WIN_CONSOLE_BUG 148280304Sjkim# endif 149280304Sjkim# else 150280304Sjkim# define get_last_sys_error() errno 151280304Sjkim# define clear_sys_error() errno=0 152280304Sjkim# endif 15355714Skris 154280304Sjkim# if defined(WINDOWS) 155280304Sjkim# define get_last_socket_error() WSAGetLastError() 156280304Sjkim# define clear_socket_error() WSASetLastError(0) 157280304Sjkim# define readsocket(s,b,n) recv((s),(b),(n),0) 158280304Sjkim# define writesocket(s,b,n) send((s),(b),(n),0) 159280304Sjkim# elif defined(__DJGPP__) 160280304Sjkim# define WATT32 161280304Sjkim# define get_last_socket_error() errno 162280304Sjkim# define clear_socket_error() errno=0 163280304Sjkim# define closesocket(s) close_s(s) 164280304Sjkim# define readsocket(s,b,n) read_s(s,b,n) 165280304Sjkim# define writesocket(s,b,n) send(s,b,n,0) 166280304Sjkim# elif defined(MAC_OS_pre_X) 167280304Sjkim# define get_last_socket_error() errno 168280304Sjkim# define clear_socket_error() errno=0 169280304Sjkim# define closesocket(s) MacSocket_close(s) 170280304Sjkim# define readsocket(s,b,n) MacSocket_recv((s),(b),(n),true) 171280304Sjkim# define writesocket(s,b,n) MacSocket_send((s),(b),(n)) 172280304Sjkim# elif defined(OPENSSL_SYS_VMS) 173280304Sjkim# define get_last_socket_error() errno 174280304Sjkim# define clear_socket_error() errno=0 175280304Sjkim# define ioctlsocket(a,b,c) ioctl(a,b,c) 176280304Sjkim# define closesocket(s) close(s) 177280304Sjkim# define readsocket(s,b,n) recv((s),(b),(n),0) 178280304Sjkim# define writesocket(s,b,n) send((s),(b),(n),0) 179280304Sjkim# elif defined(OPENSSL_SYS_VXWORKS) 180280304Sjkim# define get_last_socket_error() errno 181280304Sjkim# define clear_socket_error() errno=0 182280304Sjkim# define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c)) 183280304Sjkim# define closesocket(s) close(s) 184280304Sjkim# define readsocket(s,b,n) read((s),(b),(n)) 185280304Sjkim# define writesocket(s,b,n) write((s),(char *)(b),(n)) 186280304Sjkim# elif defined(OPENSSL_SYS_BEOS_R5) 187280304Sjkim# define get_last_socket_error() errno 188280304Sjkim# define clear_socket_error() errno=0 189280304Sjkim# define FIONBIO SO_NONBLOCK 190280304Sjkim# define ioctlsocket(a,b,c) setsockopt((a),SOL_SOCKET,(b),(c),sizeof(*(c))) 191280304Sjkim# define readsocket(s,b,n) recv((s),(b),(n),0) 192280304Sjkim# define writesocket(s,b,n) send((s),(b),(n),0) 193280304Sjkim# elif defined(OPENSSL_SYS_NETWARE) 194280304Sjkim# if defined(NETWARE_BSDSOCK) 195280304Sjkim# define get_last_socket_error() errno 196280304Sjkim# define clear_socket_error() errno=0 197280304Sjkim# define closesocket(s) close(s) 198280304Sjkim# define ioctlsocket(a,b,c) ioctl(a,b,c) 199280304Sjkim# if defined(NETWARE_LIBC) 200280304Sjkim# define readsocket(s,b,n) recv((s),(b),(n),0) 201280304Sjkim# define writesocket(s,b,n) send((s),(b),(n),0) 202280304Sjkim# else 203280304Sjkim# define readsocket(s,b,n) recv((s),(char*)(b),(n),0) 204280304Sjkim# define writesocket(s,b,n) send((s),(char*)(b),(n),0) 205280304Sjkim# endif 206280304Sjkim# else 207280304Sjkim# define get_last_socket_error() WSAGetLastError() 208280304Sjkim# define clear_socket_error() WSASetLastError(0) 209280304Sjkim# define readsocket(s,b,n) recv((s),(b),(n),0) 210280304Sjkim# define writesocket(s,b,n) send((s),(b),(n),0) 211280304Sjkim# endif 212280304Sjkim# else 213280304Sjkim# define get_last_socket_error() errno 214280304Sjkim# define clear_socket_error() errno=0 215280304Sjkim# define ioctlsocket(a,b,c) ioctl(a,b,c) 216280304Sjkim# define closesocket(s) close(s) 217280304Sjkim# define readsocket(s,b,n) read((s),(b),(n)) 218280304Sjkim# define writesocket(s,b,n) write((s),(b),(n)) 219280304Sjkim# endif 22055714Skris 221280304Sjkim# ifdef WIN16 /* never the case */ 222280304Sjkim# define MS_CALLBACK _far _loadds 223280304Sjkim# define MS_FAR _far 224280304Sjkim# else 22555714Skris# define MS_CALLBACK 22655714Skris# define MS_FAR 227280304Sjkim# endif 22855714Skris 229280304Sjkim# ifdef OPENSSL_NO_STDIO 230160814Ssimon# undef OPENSSL_NO_FP_API 231109998Smarkm# define OPENSSL_NO_FP_API 232280304Sjkim# endif 23355714Skris 234280304Sjkim# if (defined(WINDOWS) || defined(MSDOS)) 23555714Skris 236109998Smarkm# ifdef __DJGPP__ 237280304Sjkim# include <unistd.h> 238280304Sjkim# include <sys/stat.h> 239280304Sjkim# include <sys/socket.h> 240280304Sjkim# include <tcp.h> 241280304Sjkim# include <netdb.h> 242280304Sjkim# define _setmode setmode 243280304Sjkim# define _O_TEXT O_TEXT 244280304Sjkim# define _O_BINARY O_BINARY 245280304Sjkim# undef DEVRANDOM 246280304Sjkim# define DEVRANDOM "/dev/urandom\x24" 247280304Sjkim# endif /* __DJGPP__ */ 248109998Smarkm 24959191Skris# ifndef S_IFDIR 250280304Sjkim# define S_IFDIR _S_IFDIR 25159191Skris# endif 25255714Skris 25359191Skris# ifndef S_IFMT 254280304Sjkim# define S_IFMT _S_IFMT 25559191Skris# endif 25655714Skris 257109998Smarkm# if !defined(WINNT) && !defined(__DJGPP__) 258280304Sjkim# define NO_SYSLOG 25959191Skris# endif 26059191Skris# define NO_DIRENT 26155714Skris 26255714Skris# ifdef WINDOWS 263280304Sjkim# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT) 264160814Ssimon /* 265280304Sjkim * Defining _WIN32_WINNT here in e_os.h implies certain "discipline." 266280304Sjkim * Most notably we ought to check for availability of each specific 267280304Sjkim * routine with GetProcAddress() and/or guard NT-specific calls with 268280304Sjkim * GetVersion() < 0x80000000. One can argue that in latter "or" case 269280304Sjkim * we ought to /DELAYLOAD some .DLLs in order to protect ourselves 270280304Sjkim * against run-time link errors. This doesn't seem to be necessary, 271280304Sjkim * because it turned out that already Windows 95, first non-NT Win32 272280304Sjkim * implementation, is equipped with at least NT 3.51 stubs, dummy 273280304Sjkim * routines with same name, but which do nothing. Meaning that it's 274280304Sjkim * apparently sufficient to guard "vanilla" NT calls with GetVersion 275280304Sjkim * alone, while NT 4.0 and above interfaces ought to be linked with 276280304Sjkim * GetProcAddress at run-time. 277280304Sjkim */ 278280304Sjkim# define _WIN32_WINNT 0x0400 279280304Sjkim# endif 280280304Sjkim# if !defined(OPENSSL_NO_SOCK) && defined(_WIN32_WINNT) 281238405Sjkim /* 282238405Sjkim * Just like defining _WIN32_WINNT including winsock2.h implies 283238405Sjkim * certain "discipline" for maintaining [broad] binary compatibility. 284238405Sjkim * As long as structures are invariant among Winsock versions, 285238405Sjkim * it's sufficient to check for specific Winsock2 API availability 286238405Sjkim * at run-time [DSO_global_lookup is recommended]... 287238405Sjkim */ 288280304Sjkim# include <winsock2.h> 289280304Sjkim# include <ws2tcpip.h> 290238405Sjkim /* yes, they have to be #included prior to <windows.h> */ 291280304Sjkim# endif 292280304Sjkim# include <windows.h> 293280304Sjkim# include <stdio.h> 294280304Sjkim# include <stddef.h> 295280304Sjkim# include <errno.h> 296280304Sjkim# include <string.h> 297280304Sjkim# ifdef _WIN64 298280304Sjkim# define strlen(s) _strlen31(s) 299160814Ssimon/* cut strings to 2GB */ 300276864Sjkimstatic __inline unsigned int _strlen31(const char *str) 301280304Sjkim{ 302280304Sjkim unsigned int len = 0; 303280304Sjkim while (*str && len < 0x80000000U) 304280304Sjkim str++, len++; 305280304Sjkim return len & 0x7FFFFFFF; 306280304Sjkim} 307280304Sjkim# endif 308280304Sjkim# include <malloc.h> 309280304Sjkim# if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace) 310194206Ssimon /* compensate for bug in VC6 ctype.h */ 311280304Sjkim# undef isspace 312280304Sjkim# undef isdigit 313280304Sjkim# undef isalnum 314280304Sjkim# undef isupper 315280304Sjkim# undef isxdigit 316280304Sjkim# endif 317280304Sjkim# if defined(_MSC_VER) && !defined(_DLL) && defined(stdin) 318291721Sjkim# if _MSC_VER>=1300 && _MSC_VER<1600 319280304Sjkim# undef stdin 320280304Sjkim# undef stdout 321280304Sjkim# undef stderr 322280304SjkimFILE *__iob_func(); 323280304Sjkim# define stdin (&__iob_func()[0]) 324280304Sjkim# define stdout (&__iob_func()[1]) 325280304Sjkim# define stderr (&__iob_func()[2]) 326291721Sjkim# elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049) 327280304Sjkim# undef stdin 328280304Sjkim# undef stdout 329280304Sjkim# undef stderr 330280304Sjkim /* 331280304Sjkim * pre-1300 has __p__iob(), but it's available only in msvcrt.lib, 332280304Sjkim * or in other words with /MD. Declaring implicit import, i.e. with 333280304Sjkim * _imp_ prefix, works correctly with all compiler options, but 334280304Sjkim * without /MD results in LINK warning LNK4049: 'locally defined 335280304Sjkim * symbol "__iob" imported'. 336194206Ssimon */ 337280304Sjkimextern FILE *_imp___iob; 338280304Sjkim# define stdin (&_imp___iob[0]) 339280304Sjkim# define stdout (&_imp___iob[1]) 340280304Sjkim# define stderr (&_imp___iob[2]) 341194206Ssimon# endif 342280304Sjkim# endif 34355714Skris# endif 34455714Skris# include <io.h> 34555714Skris# include <fcntl.h> 34655714Skris 347109998Smarkm# ifdef OPENSSL_SYS_WINCE 348280304Sjkim# define OPENSSL_NO_POSIX_IO 349109998Smarkm# endif 350109998Smarkm 35159191Skris# if defined (__BORLANDC__) 352280304Sjkim# define _setmode setmode 353280304Sjkim# define _O_TEXT O_TEXT 354280304Sjkim# define _O_BINARY O_BINARY 355280304Sjkim# define _int64 __int64 356280304Sjkim# define _kbhit kbhit 35759191Skris# endif 35859191Skris 359238405Sjkim# define EXIT(n) exit(n) 36055714Skris# define LIST_SEPARATOR_CHAR ';' 36159191Skris# ifndef X_OK 362280304Sjkim# define X_OK 0 36359191Skris# endif 36459191Skris# ifndef W_OK 365280304Sjkim# define W_OK 2 36659191Skris# endif 36759191Skris# ifndef R_OK 368280304Sjkim# define R_OK 4 36959191Skris# endif 370280304Sjkim# define OPENSSL_CONF "openssl.cnf" 371280304Sjkim# define SSLEAY_CONF OPENSSL_CONF 372280304Sjkim# define NUL_DEV "nul" 373280304Sjkim# define RFILE ".rnd" 374109998Smarkm# ifdef OPENSSL_SYS_WINCE 375280304Sjkim# define DEFAULT_HOME "" 376109998Smarkm# else 377280304Sjkim# define DEFAULT_HOME "C:" 378109998Smarkm# endif 37955714Skris 380277597Sjkim/* Avoid Visual Studio 13 GetVersion deprecated problems */ 381280304Sjkim# if defined(_MSC_VER) && _MSC_VER>=1800 382280304Sjkim# define check_winnt() (1) 383280304Sjkim# define check_win_minplat(x) (1) 384280304Sjkim# else 385280304Sjkim# define check_winnt() (GetVersion() < 0x80000000) 386280304Sjkim# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x)) 387280304Sjkim# endif 388264331Sjkim 389280304Sjkim# else /* The non-microsoft world */ 39055714Skris 391109998Smarkm# ifdef OPENSSL_SYS_VMS 392280304Sjkim# define VMS 1 393280304Sjkim /* 394280304Sjkim * some programs don't include stdlib, so exit() and others give implicit 395280304Sjkim * function warnings 396280304Sjkim */ 397280304Sjkim# include <stdlib.h> 398280304Sjkim# if defined(__DECC) 399280304Sjkim# include <unistd.h> 400280304Sjkim# else 401280304Sjkim# include <unixlib.h> 402280304Sjkim# endif 403280304Sjkim# define OPENSSL_CONF "openssl.cnf" 404280304Sjkim# define SSLEAY_CONF OPENSSL_CONF 405280304Sjkim# define RFILE ".rnd" 406280304Sjkim# define LIST_SEPARATOR_CHAR ',' 407280304Sjkim# define NUL_DEV "NLA0:" 408109998Smarkm /* We don't have any well-defined random devices on VMS, yet... */ 409280304Sjkim# undef DEVRANDOM 410280304Sjkim /*- 411280304Sjkim We need to do this since VMS has the following coding on status codes: 41259191Skris 41359191Skris Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ... 41459191Skris The important thing to know is that odd numbers are considered 415280304Sjkim good, while even ones are considered errors. 41659191Skris Bits 3-15: actual status number 41759191Skris Bits 16-27: facility number. 0 is considered "unknown" 41859191Skris Bits 28-31: control bits. If bit 28 is set, the shell won't try to 41959191Skris output the message (which, for random codes, just looks ugly) 42059191Skris 42159191Skris So, what we do here is to change 0 to 1 to get the default success status, 42259191Skris and everything else is shifted up to fit into the status number field, and 42359191Skris the status is tagged as an error, which I believe is what is wanted here. 42459191Skris -- Richard Levitte 42559191Skris */ 426280304Sjkim# define EXIT(n) do { int __VMS_EXIT = n; \ 42759191Skris if (__VMS_EXIT == 0) \ 428280304Sjkim __VMS_EXIT = 1; \ 429280304Sjkim else \ 430280304Sjkim __VMS_EXIT = (n << 3) | 2; \ 43155714Skris __VMS_EXIT |= 0x10000000; \ 432280304Sjkim exit(__VMS_EXIT); } while(0) 433280304Sjkim# define NO_SYS_PARAM_H 434160814Ssimon 435160814Ssimon# elif defined(OPENSSL_SYS_NETWARE) 436280304Sjkim# include <fcntl.h> 437280304Sjkim# include <unistd.h> 438280304Sjkim# define NO_SYS_TYPES_H 439280304Sjkim# undef DEVRANDOM 440280304Sjkim# ifdef NETWARE_CLIB 441280304Sjkim# define getpid GetThreadID 442280304Sjkimextern int GetThreadID(void); 443194206Ssimon/* # include <conio.h> */ 444280304Sjkimextern int kbhit(void); 445280304Sjkim# else 446280304Sjkim# include <screen.h> 447280304Sjkim# endif 448280304Sjkim# define NO_SYSLOG 449280304Sjkim# define _setmode setmode 450280304Sjkim# define _kbhit kbhit 451280304Sjkim# define _O_TEXT O_TEXT 452280304Sjkim# define _O_BINARY O_BINARY 453280304Sjkim# define OPENSSL_CONF "openssl.cnf" 454280304Sjkim# define SSLEAY_CONF OPENSSL_CONF 455280304Sjkim# define RFILE ".rnd" 456280304Sjkim# define LIST_SEPARATOR_CHAR ';' 457280304Sjkim# define EXIT(n) { if (n) printf("ERROR: %d\n", (int)n); exit(n); } 458160814Ssimon 45955714Skris# else 46055714Skris /* !defined VMS */ 461280304Sjkim# ifdef OPENSSL_SYS_MPE 462280304Sjkim# define NO_SYS_PARAM_H 463280304Sjkim# endif 464280304Sjkim# ifdef OPENSSL_UNISTD 465280304Sjkim# include OPENSSL_UNISTD 466280304Sjkim# else 467280304Sjkim# include <unistd.h> 468280304Sjkim# endif 469280304Sjkim# ifndef NO_SYS_TYPES_H 470280304Sjkim# include <sys/types.h> 471280304Sjkim# endif 472280304Sjkim# if defined(NeXT) || defined(OPENSSL_SYS_NEWS4) 473280304Sjkim# define pid_t int /* pid_t is missing on NEXTSTEP/OPENSTEP 474280304Sjkim * (unless when compiling with 475280304Sjkim * -D_POSIX_SOURCE, which doesn't work for 476280304Sjkim * us) */ 477280304Sjkim# endif 478280304Sjkim# ifdef OPENSSL_SYS_NEWS4 /* setvbuf is missing on mips-sony-bsd */ 479280304Sjkim# define setvbuf(a, b, c, d) setbuffer((a), (b), (d)) 480280304Sjkimtypedef unsigned long clock_t; 481280304Sjkim# endif 482280304Sjkim# ifdef OPENSSL_SYS_WIN32_CYGWIN 483280304Sjkim# include <io.h> 484280304Sjkim# include <fcntl.h> 485280304Sjkim# endif 48655714Skris 487280304Sjkim# define OPENSSL_CONF "openssl.cnf" 488280304Sjkim# define SSLEAY_CONF OPENSSL_CONF 489280304Sjkim# define RFILE ".rnd" 490280304Sjkim# define LIST_SEPARATOR_CHAR ':' 491280304Sjkim# define NUL_DEV "/dev/null" 492280304Sjkim# define EXIT(n) exit(n) 49355714Skris# endif 49455714Skris 495280304Sjkim# define SSLeay_getpid() getpid() 49655714Skris 497280304Sjkim# endif 49855714Skris 49955714Skris/*************/ 50055714Skris 501280304Sjkim# ifdef USE_SOCKETS 50255714Skris# if defined(WINDOWS) || defined(MSDOS) 50355714Skris /* windows world */ 50455714Skris 505280304Sjkim# ifdef OPENSSL_NO_SOCK 506280304Sjkim# define SSLeay_Write(a,b,c) (-1) 507280304Sjkim# define SSLeay_Read(a,b,c) (-1) 508280304Sjkim# define SHUTDOWN(fd) close(fd) 509280304Sjkim# define SHUTDOWN2(fd) close(fd) 510280304Sjkim# elif !defined(__DJGPP__) 511280304Sjkim# if defined(_WIN32_WCE) && _WIN32_WCE<410 512280304Sjkim# define getservbyname _masked_declaration_getservbyname 513280304Sjkim# endif 514280304Sjkim# if !defined(IPPROTO_IP) 515238405Sjkim /* winsock[2].h was included already? */ 516280304Sjkim# include <winsock.h> 517280304Sjkim# endif 518280304Sjkim# ifdef getservbyname 519280304Sjkim# undef getservbyname 520238405Sjkim /* this is used to be wcecompat/include/winsock_extras.h */ 521280304Sjkimstruct servent *PASCAL getservbyname(const char *, const char *); 522280304Sjkim# endif 523238405Sjkim 524280304Sjkim# ifdef _WIN64 525160814Ssimon/* 526160814Ssimon * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because 527160814Ssimon * the value constitutes an index in per-process table of limited size 528160814Ssimon * and not a real pointer. 529160814Ssimon */ 530280304Sjkim# define socket(d,t,p) ((int)socket(d,t,p)) 531280304Sjkim# define accept(s,f,l) ((int)accept(s,f,l)) 53255714Skris# endif 533280304Sjkim# define SSLeay_Write(a,b,c) send((a),(b),(c),0) 534280304Sjkim# define SSLeay_Read(a,b,c) recv((a),(b),(c),0) 535280304Sjkim# define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); } 536280304Sjkim# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); } 537280304Sjkim# else 538280304Sjkim# define SSLeay_Write(a,b,c) write_s(a,b,c,0) 539280304Sjkim# define SSLeay_Read(a,b,c) read_s(a,b,c) 540280304Sjkim# define SHUTDOWN(fd) close_s(fd) 541280304Sjkim# define SHUTDOWN2(fd) close_s(fd) 542280304Sjkim# endif 54355714Skris 54459191Skris# elif defined(MAC_OS_pre_X) 54555714Skris 546280304Sjkim# include "MacSocket.h" 547280304Sjkim# define SSLeay_Write(a,b,c) MacSocket_send((a),(b),(c)) 548280304Sjkim# define SSLeay_Read(a,b,c) MacSocket_recv((a),(b),(c),true) 549280304Sjkim# define SHUTDOWN(fd) MacSocket_close(fd) 550280304Sjkim# define SHUTDOWN2(fd) MacSocket_close(fd) 55159191Skris 552160814Ssimon# elif defined(OPENSSL_SYS_NETWARE) 553280304Sjkim /* 554280304Sjkim * NetWare uses the WinSock2 interfaces by default, but can be 555280304Sjkim * configured for BSD 556280304Sjkim */ 557280304Sjkim# if defined(NETWARE_BSDSOCK) 558280304Sjkim# include <sys/socket.h> 559280304Sjkim# include <netinet/in.h> 560280304Sjkim# include <sys/time.h> 561280304Sjkim# if defined(NETWARE_CLIB) 562280304Sjkim# include <sys/bsdskt.h> 563280304Sjkim# else 564280304Sjkim# include <sys/select.h> 565280304Sjkim# endif 566280304Sjkim# define INVALID_SOCKET (int)(~0) 567280304Sjkim# else 568280304Sjkim# include <novsock2.h> 569280304Sjkim# endif 570280304Sjkim# define SSLeay_Write(a,b,c) send((a),(b),(c),0) 571280304Sjkim# define SSLeay_Read(a,b,c) recv((a),(b),(c),0) 572280304Sjkim# define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); } 573280304Sjkim# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); } 574160814Ssimon 57555714Skris# else 57655714Skris 577280304Sjkim# ifndef NO_SYS_PARAM_H 578280304Sjkim# include <sys/param.h> 579280304Sjkim# endif 580280304Sjkim# ifdef OPENSSL_SYS_VXWORKS 581280304Sjkim# include <time.h> 582280304Sjkim# elif !defined(OPENSSL_SYS_MPE) 583280304Sjkim# include <sys/time.h> /* Needed under linux for FD_XXX */ 584280304Sjkim# endif 58555714Skris 586280304Sjkim# include <netdb.h> 587280304Sjkim# if defined(OPENSSL_SYS_VMS_NODECC) 588280304Sjkim# include <socket.h> 589280304Sjkim# include <in.h> 590280304Sjkim# include <inet.h> 591280304Sjkim# else 592280304Sjkim# include <sys/socket.h> 593280304Sjkim# ifdef FILIO_H 594280304Sjkim# include <sys/filio.h> /* Added for FIONBIO under unixware */ 59555714Skris# endif 596280304Sjkim# include <netinet/in.h> 597280304Sjkim# if !defined(OPENSSL_SYS_BEOS_R5) 598280304Sjkim# include <arpa/inet.h> 599238405Sjkim# endif 600280304Sjkim# endif 60155714Skris 602280304Sjkim# if defined(NeXT) || defined(_NEXT_SOURCE) 603280304Sjkim# include <sys/fcntl.h> 604280304Sjkim# include <sys/types.h> 605280304Sjkim# endif 60655714Skris 607280304Sjkim# ifdef OPENSSL_SYS_AIX 608280304Sjkim# include <sys/select.h> 609280304Sjkim# endif 61055714Skris 611280304Sjkim# ifdef __QNX__ 612280304Sjkim# include <sys/select.h> 613280304Sjkim# endif 61468651Skris 615291721Sjkim# if defined(__sun) || defined(sun) 616280304Sjkim# include <sys/filio.h> 617280304Sjkim# else 618280304Sjkim# ifndef VMS 619280304Sjkim# include <sys/ioctl.h> 62055714Skris# else 621280304Sjkim /* ioctl is only in VMS > 7.0 and when socketshr is not used */ 622280304Sjkim# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000) 623280304Sjkim# include <sys/ioctl.h> 624280304Sjkim# endif 62555714Skris# endif 626280304Sjkim# endif 62755714Skris 628280304Sjkim# ifdef VMS 629280304Sjkim# include <unixio.h> 630280304Sjkim# if defined(TCPIP_TYPE_SOCKETSHR) 631280304Sjkim# include <socketshr.h> 63255714Skris# endif 633280304Sjkim# endif 63455714Skris 635280304Sjkim# define SSLeay_Read(a,b,c) read((a),(b),(c)) 636280304Sjkim# define SSLeay_Write(a,b,c) write((a),(b),(c)) 637280304Sjkim# define SHUTDOWN(fd) { shutdown((fd),0); closesocket((fd)); } 638280304Sjkim# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket((fd)); } 639280304Sjkim# ifndef INVALID_SOCKET 640280304Sjkim# define INVALID_SOCKET (-1) 641280304Sjkim# endif /* INVALID_SOCKET */ 64255714Skris# endif 64355714Skris 644280304Sjkim/* 645280304Sjkim * Some IPv6 implementations are broken, disable them in known bad versions. 646238405Sjkim */ 647238405Sjkim# if !defined(OPENSSL_USE_IPV6) 648280304Sjkim# if defined(AF_INET6) && !defined(OPENSSL_SYS_BEOS_BONE) && !defined(NETWARE_CLIB) 649280304Sjkim# define OPENSSL_USE_IPV6 1 650280304Sjkim# else 651280304Sjkim# define OPENSSL_USE_IPV6 0 652280304Sjkim# endif 65359191Skris# endif 654238405Sjkim 655280304Sjkim# endif 65659191Skris 657291721Sjkim# if (defined(__sun) || defined(sun)) && !defined(__svr4__) && !defined(__SVR4) 65889837Skris /* include headers first, so our defines don't break it */ 659280304Sjkim# include <stdlib.h> 660280304Sjkim# include <string.h> 66168651Skris /* bcopy can handle overlapping moves according to SunOS 4.1.4 manpage */ 662280304Sjkim# define memmove(s1,s2,n) bcopy((s2),(s1),(n)) 663280304Sjkim# define strtoul(s,e,b) ((unsigned long int)strtol((s),(e),(b))) 664280304Sjkimextern char *sys_errlist[]; 665280304Sjkimextern int sys_nerr; 666280304Sjkim# define strerror(errnum) \ 667280304Sjkim (((errnum)<0 || (errnum)>=sys_nerr) ? NULL : sys_errlist[errnum]) 668160814Ssimon /* Being signed SunOS 4.x memcpy breaks ASN1_OBJECT table lookup */ 669280304Sjkim# include "crypto/o_str.h" 670280304Sjkim# define memcmp OPENSSL_memcmp 671280304Sjkim# endif 67268651Skris 673280304Sjkim# ifndef OPENSSL_EXIT 674280304Sjkim# if defined(MONOLITH) && !defined(OPENSSL_C) 675280304Sjkim# define OPENSSL_EXIT(n) return(n) 676280304Sjkim# else 677280304Sjkim# define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0) 678280304Sjkim# endif 679109998Smarkm# endif 680109998Smarkm 68155714Skris/***********************************************/ 68255714Skris 683280304Sjkim# define DG_GCC_BUG /* gcc < 2.6.3 on DGUX */ 68455714Skris 685280304Sjkim# ifdef sgi 686280304Sjkim# define IRIX_CC_BUG /* all version of IRIX I've tested (4.* 5.*) */ 687280304Sjkim# endif 688280304Sjkim# ifdef OPENSSL_SYS_SNI 689280304Sjkim# define IRIX_CC_BUG /* CDS++ up to V2.0Bsomething suffered from 690280304Sjkim * the same bug. */ 691280304Sjkim# endif 69255714Skris 693280304Sjkim# if defined(OPENSSL_SYS_WINDOWS) 694142425Snectar# define strcasecmp _stricmp 695142425Snectar# define strncasecmp _strnicmp 696280304Sjkim# elif defined(OPENSSL_SYS_VMS) 697142425Snectar/* VMS below version 7.0 doesn't have strcasecmp() */ 698142425Snectar# include "o_str.h" 699142425Snectar# define strcasecmp OPENSSL_strcasecmp 700142425Snectar# define strncasecmp OPENSSL_strncasecmp 701160814Ssimon# define OPENSSL_IMPLEMENTS_strncasecmp 702280304Sjkim# elif defined(OPENSSL_SYS_OS2) && defined(__EMX__) 703142425Snectar# define strcasecmp stricmp 704142425Snectar# define strncasecmp strnicmp 705280304Sjkim# elif defined(OPENSSL_SYS_NETWARE) 706194206Ssimon# include <string.h> 707194206Ssimon# if defined(NETWARE_CLIB) 708280304Sjkim# define strcasecmp stricmp 709280304Sjkim# define strncasecmp strnicmp 710280304Sjkim# endif /* NETWARE_CLIB */ 711280304Sjkim# endif 712142425Snectar 713280304Sjkim# if defined(OPENSSL_SYS_OS2) && defined(__EMX__) 714280304Sjkim# include <io.h> 715280304Sjkim# include <fcntl.h> 716280304Sjkim# define NO_SYSLOG 717280304Sjkim# endif 718109998Smarkm 719109998Smarkm/* vxworks */ 720280304Sjkim# if defined(OPENSSL_SYS_VXWORKS) 721280304Sjkim# include <ioLib.h> 722280304Sjkim# include <tickLib.h> 723280304Sjkim# include <sysLib.h> 724109998Smarkm 725280304Sjkim# define TTY_STRUCT int 726109998Smarkm 727280304Sjkim# define sleep(a) taskDelay((a) * sysClkRateGet()) 72855714Skris 729280304Sjkim# include <vxWorks.h> 730280304Sjkim# include <sockLib.h> 731280304Sjkim# include <taskLib.h> 732109998Smarkm 733280304Sjkim# define getpid taskIdSelf 734109998Smarkm 735280304Sjkim/* 736280304Sjkim * NOTE: these are implemented by helpers in database app! if the database is 737280304Sjkim * not linked, we need to implement them elswhere 738280304Sjkim */ 739109998Smarkmstruct hostent *gethostbyname(const char *name); 740109998Smarkmstruct hostent *gethostbyaddr(const char *addr, int length, int type); 741109998Smarkmstruct servent *getservbyname(const char *name, const char *proto); 742109998Smarkm 743280304Sjkim# endif 744109998Smarkm/* end vxworks */ 745109998Smarkm 746238405Sjkim/* beos */ 747280304Sjkim# if defined(OPENSSL_SYS_BEOS_R5) 748280304Sjkim# define SO_ERROR 0 749280304Sjkim# define NO_SYS_UN 750280304Sjkim# define IPPROTO_IP 0 751280304Sjkim# include <OS.h> 752280304Sjkim# endif 753238405Sjkim 754280304Sjkim# if !defined(inline) && !defined(__cplusplus) 755280304Sjkim# if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L 756276864Sjkim /* do nothing, inline works */ 757280304Sjkim# elif defined(__GNUC__) && __GNUC__>=2 758280304Sjkim# define inline __inline__ 759280304Sjkim# elif defined(_MSC_VER) 760276864Sjkim /* 761276864Sjkim * Visual Studio: inline is available in C++ only, however 762276864Sjkim * __inline is available for C, see 763276864Sjkim * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx 764276864Sjkim */ 765280304Sjkim# define inline __inline 766280304Sjkim# else 767280304Sjkim# define inline 768280304Sjkim# endif 769276864Sjkim# endif 770238405Sjkim 77155714Skris#ifdef __cplusplus 77255714Skris} 77355714Skris#endif 77455714Skris 77555714Skris#endif 776