1/* 2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. 3 * 4 * The contents of this file constitute Original Code as defined in and are 5 * subject to the Apple Public Source License Version 1.2 (the 'License'). 6 * You may not use this file except in compliance with the License. Please obtain 7 * a copy of the License at http://www.apple.com/publicsource and read it before 8 * using this file. 9 * 10 * This Original Code and all software distributed under the License are 11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS 12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the 15 * specific language governing rights and limitations under the License. 16 */ 17 18 19/* e_os.h */ 20/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 21 * All rights reserved. 22 * 23 * This package is an SSL implementation written 24 * by Eric Young (eay@cryptsoft.com). 25 * The implementation was written so as to conform with Netscapes SSL. 26 * 27 * This library is free for commercial and non-commercial use as long as 28 * the following conditions are aheared to. The following conditions 29 * apply to all code found in this distribution, be it the RC4, RSA, 30 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 31 * included with this distribution is covered by the same copyright terms 32 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 33 * 34 * Copyright remains Eric Young's, and as such any Copyright notices in 35 * the code are not to be removed. 36 * If this package is used in a product, Eric Young should be given attribution 37 * as the author of the parts of the library used. 38 * This can be in the form of a textual message at program startup or 39 * in documentation (online or textual) provided with the package. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. All advertising materials mentioning features or use of this software 50 * must display the following acknowledgement: 51 * "This product includes cryptographic software written by 52 * Eric Young (eay@cryptsoft.com)" 53 * The word 'cryptographic' can be left out if the rouines from the library 54 * being used are not cryptographic related :-). 55 * 4. If you include any Windows specific code (or a derivative thereof) from 56 * the apps directory (application code) you must include an acknowledgement: 57 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 58 * 59 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * The licence and distribution terms for any publically available version or 72 * derivative of this code cannot be changed. i.e. this code cannot simply be 73 * copied and put under another distribution licence 74 * [including the GNU Public Licence.] 75 */ 76 77#ifndef HEADER_E_OS_H 78#define HEADER_E_OS_H 79 80#include <openssl/opensslconf.h> 81 82#include <openssl/e_os2.h> 83/* <openssl/e_os2.h> contains what we can justify to make visible 84 * to the outside; this file e_os.h is not part of the exported 85 * interface. */ 86 87#ifdef __cplusplus 88extern "C" { 89#endif 90 91/* Used to checking reference counts, most while doing perl5 stuff :-) */ 92#ifdef REF_PRINT 93#undef REF_PRINT 94#define REF_PRINT(a,b) fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a) 95#endif 96 97#ifndef DEVRANDOM 98/* set this to your 'random' device if you have one. 99 * My default, we will try to read this file */ 100#define DEVRANDOM "/dev/urandom" 101#endif 102 103#if defined(__MWERKS__) && defined(macintosh) 104# if macintosh==1 105# ifndef MAC_OS_GUSI_SOURCE 106# define MAC_OS_pre_X 107# define NO_SYS_TYPES_H 108# endif 109# define NO_SYS_PARAM_H 110# define NO_CHMOD 111# define NO_SYSLOG 112# undef DEVRANDOM 113# define GETPID_IS_MEANINGLESS 114# endif 115#endif 116 117/******************************************************************** 118 The Microsoft section 119 ********************************************************************/ 120/* The following is used becaue of the small stack in some 121 * Microsoft operating systems */ 122#if defined(WIN16) || defined(MSDOS) 123# define MS_STATIC static 124#else 125# define MS_STATIC 126#endif 127 128#if defined(_WIN32) && !defined(WIN32) 129# define WIN32 130#endif 131 132#if defined(WIN32) || defined(WIN16) 133# ifndef WINDOWS 134# define WINDOWS 135# endif 136# ifndef MSDOS 137# define MSDOS 138# endif 139#endif 140 141#if defined(MSDOS) && !defined(GETPID_IS_MEANINGLESS) 142# define GETPID_IS_MEANINGLESS 143#endif 144 145#ifdef WIN32 146#define get_last_sys_error() GetLastError() 147#define clear_sys_error() SetLastError(0) 148#if !defined(WINNT) 149#define WIN_CONSOLE_BUG 150#endif 151#else 152#define get_last_sys_error() errno 153#define clear_sys_error() errno=0 154#endif 155 156#ifdef WINDOWS 157#define get_last_socket_error() WSAGetLastError() 158#define clear_socket_error() WSASetLastError(0) 159#define readsocket(s,b,n) recv((s),(b),(n),0) 160#define writesocket(s,b,n) send((s),(b),(n),0) 161#define EADDRINUSE WSAEADDRINUSE 162#elif defined(MAC_OS_pre_X) 163#define get_last_socket_error() errno 164#define clear_socket_error() errno=0 165#define closesocket(s) MacSocket_close(s) 166#define readsocket(s,b,n) MacSocket_recv((s),(b),(n),true) 167#define writesocket(s,b,n) MacSocket_send((s),(b),(n)) 168#else 169#define get_last_socket_error() errno 170#define clear_socket_error() errno=0 171#define ioctlsocket(a,b,c) ioctl(a,b,c) 172#define closesocket(s) close(s) 173#define readsocket(s,b,n) read((s),(b),(n)) 174#define writesocket(s,b,n) write((s),(b),(n)) 175#endif 176 177#ifdef WIN16 178# define NO_FP_API 179# define MS_CALLBACK _far _loadds 180# define MS_FAR _far 181#else 182# define MS_CALLBACK 183# define MS_FAR 184#endif 185 186#ifdef NO_STDIO 187# define NO_FP_API 188#endif 189 190#if defined(WINDOWS) || defined(MSDOS) 191 192# ifndef S_IFDIR 193# define S_IFDIR _S_IFDIR 194# endif 195 196# ifndef S_IFMT 197# define S_IFMT _S_IFMT 198# endif 199 200# if !defined(WINNT) 201# define NO_SYSLOG 202# endif 203# define NO_DIRENT 204 205# ifdef WINDOWS 206# include <windows.h> 207# include <stddef.h> 208# include <errno.h> 209# include <string.h> 210# include <malloc.h> 211# endif 212# include <io.h> 213# include <fcntl.h> 214 215# define ssize_t long 216 217# if defined (__BORLANDC__) 218# define _setmode setmode 219# define _O_TEXT O_TEXT 220# define _O_BINARY O_BINARY 221# define _int64 __int64 222# define _kbhit kbhit 223# endif 224 225# if defined(WIN16) && !defined(MONOLITH) && defined(SSLEAY) && defined(_WINEXITNOPERSIST) 226# define EXIT(n) { if (n == 0) _wsetexit(_WINEXITNOPERSIST); return(n); } 227# else 228# define EXIT(n) return(n); 229# endif 230# define LIST_SEPARATOR_CHAR ';' 231# ifndef X_OK 232# define X_OK 0 233# endif 234# ifndef W_OK 235# define W_OK 2 236# endif 237# ifndef R_OK 238# define R_OK 4 239# endif 240# define OPENSSL_CONF "openssl.cnf" 241# define SSLEAY_CONF OPENSSL_CONF 242# define NUL_DEV "nul" 243# define RFILE ".rnd" 244 245#else /* The non-microsoft world world */ 246 247# if defined(__VMS) && !defined(VMS) 248# define VMS 1 249# endif 250 251# ifdef VMS 252 /* some programs don't include stdlib, so exit() and others give implicit 253 function warnings */ 254# include <stdlib.h> 255# if defined(__DECC) 256# include <unistd.h> 257# else 258# include <unixlib.h> 259# endif 260# define OPENSSL_CONF "openssl.cnf" 261# define SSLEAY_CONF OPENSSL_CONF 262# define RFILE ".rnd" 263# define LIST_SEPARATOR_CHAR ',' 264# define NUL_DEV "NLA0:" 265 /* We need to do this since VMS has the following coding on status codes: 266 267 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ... 268 The important thing to know is that odd numbers are considered 269 good, while even ones are considered errors. 270 Bits 3-15: actual status number 271 Bits 16-27: facility number. 0 is considered "unknown" 272 Bits 28-31: control bits. If bit 28 is set, the shell won't try to 273 output the message (which, for random codes, just looks ugly) 274 275 So, what we do here is to change 0 to 1 to get the default success status, 276 and everything else is shifted up to fit into the status number field, and 277 the status is tagged as an error, which I believe is what is wanted here. 278 -- Richard Levitte 279 */ 280# if !defined(MONOLITH) || defined(OPENSSL_C) 281# define EXIT(n) do { int __VMS_EXIT = n; \ 282 if (__VMS_EXIT == 0) \ 283 __VMS_EXIT = 1; \ 284 else \ 285 __VMS_EXIT = (n << 3) | 2; \ 286 __VMS_EXIT |= 0x10000000; \ 287 exit(__VMS_EXIT); \ 288 return(__VMS_EXIT); } while(0) 289# else 290# define EXIT(n) return(n) 291# endif 292# define NO_SYS_PARAM_H 293# else 294 /* !defined VMS */ 295# ifdef OPENSSL_UNISTD 296# include OPENSSL_UNISTD 297# else 298# include <unistd.h> 299# endif 300# ifndef NO_SYS_TYPES_H 301# include <sys/types.h> 302# endif 303# ifdef NeXT 304# define pid_t int /* pid_t is missing on NEXTSTEP/OPENSTEP 305 * (unless when compiling with -D_POSIX_SOURCE, 306 * which doesn't work for us) */ 307# define ssize_t int /* ditto */ 308# endif 309 310# define OPENSSL_CONF "openssl.cnf" 311# define SSLEAY_CONF OPENSSL_CONF 312# define RFILE ".rnd" 313# define LIST_SEPARATOR_CHAR ':' 314# define NUL_DEV "/dev/null" 315# ifndef MONOLITH 316# define EXIT(n) exit(n); return(n) 317# else 318# define EXIT(n) return(n) 319# endif 320# endif 321 322# define SSLeay_getpid() getpid() 323 324#endif 325 326 327/*************/ 328 329#ifdef USE_SOCKETS 330# if defined(WINDOWS) || defined(MSDOS) 331 /* windows world */ 332 333# ifdef NO_SOCK 334# define SSLeay_Write(a,b,c) (-1) 335# define SSLeay_Read(a,b,c) (-1) 336# define SHUTDOWN(fd) close(fd) 337# define SHUTDOWN2(fd) close(fd) 338# else 339# include <winsock.h> 340extern HINSTANCE _hInstance; 341# define SSLeay_Write(a,b,c) send((a),(b),(c),0) 342# define SSLeay_Read(a,b,c) recv((a),(b),(c),0) 343# define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); } 344# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); } 345# endif 346 347# elif defined(MAC_OS_pre_X) 348 349# include "MacSocket.h" 350# define SSLeay_Write(a,b,c) MacSocket_send((a),(b),(c)) 351# define SSLeay_Read(a,b,c) MacSocket_recv((a),(b),(c),true) 352# define SHUTDOWN(fd) MacSocket_close(fd) 353# define SHUTDOWN2(fd) MacSocket_close(fd) 354 355# else 356 357# ifndef NO_SYS_PARAM_H 358# include <sys/param.h> 359# endif 360# include <sys/time.h> /* Needed under linux for FD_XXX */ 361 362# include <netdb.h> 363# if defined(VMS) && !defined(__DECC) 364# include <socket.h> 365# include <in.h> 366# else 367# include <sys/socket.h> 368# ifdef FILIO_H 369# include <sys/filio.h> /* Added for FIONBIO under unixware */ 370# endif 371# include <netinet/in.h> 372# endif 373 374# if defined(NeXT) || defined(_NEXT_SOURCE) 375# include <sys/fcntl.h> 376# include <sys/types.h> 377# endif 378 379# ifdef AIX 380# include <sys/select.h> 381# endif 382 383# if defined(sun) 384# include <sys/filio.h> 385# else 386# ifndef VMS 387# include <sys/ioctl.h> 388# else 389 /* ioctl is only in VMS > 7.0 and when socketshr is not used */ 390# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000) 391# include <sys/ioctl.h> 392# endif 393# endif 394# endif 395 396# ifdef VMS 397# include <unixio.h> 398# if defined(TCPIP_TYPE_SOCKETSHR) 399# include <socketshr.h> 400# endif 401# endif 402 403# define SSLeay_Read(a,b,c) read((a),(b),(c)) 404# define SSLeay_Write(a,b,c) write((a),(b),(c)) 405# define SHUTDOWN(fd) { shutdown((fd),0); closesocket((fd)); } 406# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket((fd)); } 407# define INVALID_SOCKET (-1) 408# endif 409#endif 410 411#if defined(__ultrix) 412# ifndef ssize_t 413# define ssize_t int 414# endif 415#endif 416 417#if defined(THREADS) || defined(sun) 418#ifndef _REENTRANT 419#define _REENTRANT 420#endif 421#endif 422 423/***********************************************/ 424 425/* do we need to do this for getenv. 426 * Just define getenv for use under windows */ 427 428#ifdef WIN16 429/* How to do this needs to be thought out a bit more.... */ 430/*char *GETENV(char *); 431#define Getenv GETENV*/ 432#define Getenv getenv 433#else 434#define Getenv getenv 435#endif 436 437#define DG_GCC_BUG /* gcc < 2.6.3 on DGUX */ 438 439#ifdef sgi 440#define IRIX_CC_BUG /* all version of IRIX I've tested (4.* 5.*) */ 441#endif 442#ifdef SNI 443#define IRIX_CC_BUG /* CDS++ up to V2.0Bsomething suffered from the same bug.*/ 444#endif 445 446#ifdef NO_MD2 447#define MD2_Init MD2Init 448#define MD2_Update MD2Update 449#define MD2_Final MD2Final 450#define MD2_DIGEST_LENGTH 16 451#endif 452#ifdef NO_MD5 453#define MD5_Init MD5Init 454#define MD5_Update MD5Update 455#define MD5_Final MD5Final 456#define MD5_DIGEST_LENGTH 16 457#endif 458 459#ifdef __cplusplus 460} 461#endif 462 463#endif 464 465