e_os.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /* e_os.h */
  2. /* Copyright (C) 1995-1998 Eric Young ([email protected])
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young ([email protected]).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson ([email protected]).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young ([email protected])"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson ([email protected])"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. #ifndef HEADER_E_OS_H
  59. # define HEADER_E_OS_H
  60. # include <openssl/opensslconf.h>
  61. # include <openssl/e_os2.h>
  62. /*
  63. * <openssl/e_os2.h> contains what we can justify to make visible to the
  64. * outside; this file e_os.h is not part of the exported interface.
  65. */
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /* Used to checking reference counts, most while doing perl5 stuff :-) */
  70. # ifdef REF_PRINT
  71. # undef REF_PRINT
  72. # define REF_PRINT(a,b) fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a)
  73. # endif
  74. # ifndef DEVRANDOM
  75. /*
  76. * set this to a comma-separated list of 'random' device files to try out. My
  77. * default, we will try to read at least one of these files
  78. */
  79. # define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
  80. # endif
  81. # ifndef DEVRANDOM_EGD
  82. /*
  83. * set this to a comma-seperated list of 'egd' sockets to try out. These
  84. * sockets will be tried in the order listed in case accessing the device
  85. * files listed in DEVRANDOM did not return enough entropy.
  86. */
  87. # define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
  88. # endif
  89. # if defined(OPENSSL_SYS_VXWORKS)
  90. # define NO_SYS_PARAM_H
  91. # define NO_CHMOD
  92. # define NO_SYSLOG
  93. # endif
  94. # if defined(OPENSSL_SYS_MACINTOSH_CLASSIC)
  95. # if macintosh==1
  96. # ifndef MAC_OS_GUSI_SOURCE
  97. # define MAC_OS_pre_X
  98. # define NO_SYS_TYPES_H
  99. # endif
  100. # define NO_SYS_PARAM_H
  101. # define NO_CHMOD
  102. # define NO_SYSLOG
  103. # undef DEVRANDOM
  104. # define GETPID_IS_MEANINGLESS
  105. # endif
  106. # endif
  107. /********************************************************************
  108. The Microsoft section
  109. ********************************************************************/
  110. /*
  111. * The following is used because of the small stack in some Microsoft
  112. * operating systems
  113. */
  114. # if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYSNAME_WIN32)
  115. # define MS_STATIC static
  116. # else
  117. # define MS_STATIC
  118. # endif
  119. # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
  120. # define WIN32
  121. # endif
  122. # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
  123. # define WINDOWS
  124. # endif
  125. # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
  126. # define MSDOS
  127. # endif
  128. # if defined(MSDOS) && !defined(GETPID_IS_MEANINGLESS)
  129. # define GETPID_IS_MEANINGLESS
  130. # endif
  131. # ifdef WIN32
  132. # define get_last_sys_error() GetLastError()
  133. # define clear_sys_error() SetLastError(0)
  134. # if !defined(WINNT)
  135. # define WIN_CONSOLE_BUG
  136. # endif
  137. # else
  138. # define get_last_sys_error() errno
  139. # define clear_sys_error() errno=0
  140. # endif
  141. # if defined(WINDOWS)
  142. # define get_last_socket_error() WSAGetLastError()
  143. # define clear_socket_error() WSASetLastError(0)
  144. # define readsocket(s,b,n) recv((s),(b),(n),0)
  145. # define writesocket(s,b,n) send((s),(b),(n),0)
  146. # elif defined(__DJGPP__)
  147. # define WATT32
  148. # define get_last_socket_error() errno
  149. # define clear_socket_error() errno=0
  150. # define closesocket(s) close_s(s)
  151. # define readsocket(s,b,n) read_s(s,b,n)
  152. # define writesocket(s,b,n) send(s,b,n,0)
  153. # elif defined(MAC_OS_pre_X)
  154. # define get_last_socket_error() errno
  155. # define clear_socket_error() errno=0
  156. # define closesocket(s) MacSocket_close(s)
  157. # define readsocket(s,b,n) MacSocket_recv((s),(b),(n),true)
  158. # define writesocket(s,b,n) MacSocket_send((s),(b),(n))
  159. # elif defined(OPENSSL_SYS_VMS)
  160. # define get_last_socket_error() errno
  161. # define clear_socket_error() errno=0
  162. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  163. # define closesocket(s) close(s)
  164. # define readsocket(s,b,n) recv((s),(b),(n),0)
  165. # define writesocket(s,b,n) send((s),(b),(n),0)
  166. # elif defined(OPENSSL_SYS_VXWORKS)
  167. # define get_last_socket_error() errno
  168. # define clear_socket_error() errno=0
  169. # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
  170. # define closesocket(s) close(s)
  171. # define readsocket(s,b,n) read((s),(b),(n))
  172. # define writesocket(s,b,n) write((s),(char *)(b),(n))
  173. # elif defined(OPENSSL_SYS_BEOS_R5)
  174. # define get_last_socket_error() errno
  175. # define clear_socket_error() errno=0
  176. # define FIONBIO SO_NONBLOCK
  177. # define ioctlsocket(a,b,c) setsockopt((a),SOL_SOCKET,(b),(c),sizeof(*(c)))
  178. # define readsocket(s,b,n) recv((s),(b),(n),0)
  179. # define writesocket(s,b,n) send((s),(b),(n),0)
  180. # elif defined(OPENSSL_SYS_NETWARE)
  181. # if defined(NETWARE_BSDSOCK)
  182. # define get_last_socket_error() errno
  183. # define clear_socket_error() errno=0
  184. # define closesocket(s) close(s)
  185. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  186. # if defined(NETWARE_LIBC)
  187. # define readsocket(s,b,n) recv((s),(b),(n),0)
  188. # define writesocket(s,b,n) send((s),(b),(n),0)
  189. # else
  190. # define readsocket(s,b,n) recv((s),(char*)(b),(n),0)
  191. # define writesocket(s,b,n) send((s),(char*)(b),(n),0)
  192. # endif
  193. # else
  194. # define get_last_socket_error() WSAGetLastError()
  195. # define clear_socket_error() WSASetLastError(0)
  196. # define readsocket(s,b,n) recv((s),(b),(n),0)
  197. # define writesocket(s,b,n) send((s),(b),(n),0)
  198. # endif
  199. # else
  200. # define get_last_socket_error() errno
  201. # define clear_socket_error() errno=0
  202. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  203. # define closesocket(s) close(s)
  204. # define readsocket(s,b,n) read((s),(b),(n))
  205. # define writesocket(s,b,n) write((s),(b),(n))
  206. # endif
  207. # ifdef WIN16 /* never the case */
  208. # define MS_CALLBACK _far _loadds
  209. # define MS_FAR _far
  210. # else
  211. # define MS_CALLBACK
  212. # define MS_FAR
  213. # endif
  214. # ifdef OPENSSL_NO_STDIO
  215. # undef OPENSSL_NO_FP_API
  216. # define OPENSSL_NO_FP_API
  217. # endif
  218. # if (defined(WINDOWS) || defined(MSDOS))
  219. # ifdef __DJGPP__
  220. # include <unistd.h>
  221. # include <sys/stat.h>
  222. # include <sys/socket.h>
  223. # include <tcp.h>
  224. # include <netdb.h>
  225. # define _setmode setmode
  226. # define _O_TEXT O_TEXT
  227. # define _O_BINARY O_BINARY
  228. # undef DEVRANDOM
  229. # define DEVRANDOM "/dev/urandom\x24"
  230. # endif /* __DJGPP__ */
  231. # ifndef S_IFDIR
  232. # define S_IFDIR _S_IFDIR
  233. # endif
  234. # ifndef S_IFMT
  235. # define S_IFMT _S_IFMT
  236. # endif
  237. # if !defined(WINNT) && !defined(__DJGPP__)
  238. # define NO_SYSLOG
  239. # endif
  240. # define NO_DIRENT
  241. # ifdef WINDOWS
  242. # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
  243. /*
  244. * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
  245. * Most notably we ought to check for availability of each specific
  246. * routine with GetProcAddress() and/or guard NT-specific calls with
  247. * GetVersion() < 0x80000000. One can argue that in latter "or" case
  248. * we ought to /DELAYLOAD some .DLLs in order to protect ourselves
  249. * against run-time link errors. This doesn't seem to be necessary,
  250. * because it turned out that already Windows 95, first non-NT Win32
  251. * implementation, is equipped with at least NT 3.51 stubs, dummy
  252. * routines with same name, but which do nothing. Meaning that it's
  253. * apparently sufficient to guard "vanilla" NT calls with GetVersion
  254. * alone, while NT 4.0 and above interfaces ought to be linked with
  255. * GetProcAddress at run-time.
  256. */
  257. # define _WIN32_WINNT 0x0400
  258. # endif
  259. # if !defined(OPENSSL_NO_SOCK) && defined(_WIN32_WINNT)
  260. /*
  261. * Just like defining _WIN32_WINNT including winsock2.h implies
  262. * certain "discipline" for maintaining [broad] binary compatibility.
  263. * As long as structures are invariant among Winsock versions,
  264. * it's sufficient to check for specific Winsock2 API availability
  265. * at run-time [DSO_global_lookup is recommended]...
  266. */
  267. # include <winsock2.h>
  268. # include <ws2tcpip.h>
  269. /* yes, they have to be #included prior to <windows.h> */
  270. # endif
  271. # include <windows.h>
  272. # include <stdio.h>
  273. # include <stddef.h>
  274. # include <errno.h>
  275. # include <string.h>
  276. # ifdef _WIN64
  277. # define strlen(s) _strlen31(s)
  278. /* cut strings to 2GB */
  279. static __inline unsigned int _strlen31(const char *str)
  280. {
  281. unsigned int len = 0;
  282. while (*str && len < 0x80000000U)
  283. str++, len++;
  284. return len & 0x7FFFFFFF;
  285. }
  286. # endif
  287. # include <malloc.h>
  288. # if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
  289. /* compensate for bug in VC6 ctype.h */
  290. # undef isspace
  291. # undef isdigit
  292. # undef isalnum
  293. # undef isupper
  294. # undef isxdigit
  295. # endif
  296. # if defined(_MSC_VER) && !defined(_DLL) && defined(stdin)
  297. # if _MSC_VER>=1300 && _MSC_VER<1600
  298. # undef stdin
  299. # undef stdout
  300. # undef stderr
  301. FILE *__iob_func();
  302. # define stdin (&__iob_func()[0])
  303. # define stdout (&__iob_func()[1])
  304. # define stderr (&__iob_func()[2])
  305. # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
  306. # undef stdin
  307. # undef stdout
  308. # undef stderr
  309. /*
  310. * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
  311. * or in other words with /MD. Declaring implicit import, i.e. with
  312. * _imp_ prefix, works correctly with all compiler options, but
  313. * without /MD results in LINK warning LNK4049: 'locally defined
  314. * symbol "__iob" imported'.
  315. */
  316. extern FILE *_imp___iob;
  317. # define stdin (&_imp___iob[0])
  318. # define stdout (&_imp___iob[1])
  319. # define stderr (&_imp___iob[2])
  320. # endif
  321. # endif
  322. # endif
  323. # include <io.h>
  324. # include <fcntl.h>
  325. # ifdef OPENSSL_SYS_WINCE
  326. # define OPENSSL_NO_POSIX_IO
  327. # endif
  328. # if defined (__BORLANDC__)
  329. # define _setmode setmode
  330. # define _O_TEXT O_TEXT
  331. # define _O_BINARY O_BINARY
  332. # define _int64 __int64
  333. # define _kbhit kbhit
  334. # endif
  335. # define EXIT(n) exit(n)
  336. # define LIST_SEPARATOR_CHAR ';'
  337. # ifndef X_OK
  338. # define X_OK 0
  339. # endif
  340. # ifndef W_OK
  341. # define W_OK 2
  342. # endif
  343. # ifndef R_OK
  344. # define R_OK 4
  345. # endif
  346. # define OPENSSL_CONF "openssl.cnf"
  347. # define SSLEAY_CONF OPENSSL_CONF
  348. # define NUL_DEV "nul"
  349. # define RFILE ".rnd"
  350. # ifdef OPENSSL_SYS_WINCE
  351. # define DEFAULT_HOME ""
  352. # else
  353. # define DEFAULT_HOME "C:"
  354. # endif
  355. /* Avoid Visual Studio 13 GetVersion deprecated problems */
  356. # if defined(_MSC_VER) && _MSC_VER>=1800
  357. # define check_winnt() (1)
  358. # define check_win_minplat(x) (1)
  359. # else
  360. # define check_winnt() (GetVersion() < 0x80000000)
  361. # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
  362. # endif
  363. # else /* The non-microsoft world */
  364. # ifdef OPENSSL_SYS_VMS
  365. # define VMS 1
  366. /*
  367. * some programs don't include stdlib, so exit() and others give implicit
  368. * function warnings
  369. */
  370. # include <stdlib.h>
  371. # if defined(__DECC)
  372. # include <unistd.h>
  373. # else
  374. # include <unixlib.h>
  375. # endif
  376. # define OPENSSL_CONF "openssl.cnf"
  377. # define SSLEAY_CONF OPENSSL_CONF
  378. # define RFILE ".rnd"
  379. # define LIST_SEPARATOR_CHAR ','
  380. # define NUL_DEV "NLA0:"
  381. /* We don't have any well-defined random devices on VMS, yet... */
  382. # undef DEVRANDOM
  383. /*-
  384. We need to do this since VMS has the following coding on status codes:
  385. Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
  386. The important thing to know is that odd numbers are considered
  387. good, while even ones are considered errors.
  388. Bits 3-15: actual status number
  389. Bits 16-27: facility number. 0 is considered "unknown"
  390. Bits 28-31: control bits. If bit 28 is set, the shell won't try to
  391. output the message (which, for random codes, just looks ugly)
  392. So, what we do here is to change 0 to 1 to get the default success status,
  393. and everything else is shifted up to fit into the status number field, and
  394. the status is tagged as an error, which I believe is what is wanted here.
  395. -- Richard Levitte
  396. */
  397. # define EXIT(n) do { int __VMS_EXIT = n; \
  398. if (__VMS_EXIT == 0) \
  399. __VMS_EXIT = 1; \
  400. else \
  401. __VMS_EXIT = (n << 3) | 2; \
  402. __VMS_EXIT |= 0x10000000; \
  403. exit(__VMS_EXIT); } while(0)
  404. # define NO_SYS_PARAM_H
  405. # elif defined(OPENSSL_SYS_NETWARE)
  406. # include <fcntl.h>
  407. # include <unistd.h>
  408. # define NO_SYS_TYPES_H
  409. # undef DEVRANDOM
  410. # ifdef NETWARE_CLIB
  411. # define getpid GetThreadID
  412. extern int GetThreadID(void);
  413. /* # include <conio.h> */
  414. extern int kbhit(void);
  415. # else
  416. # include <screen.h>
  417. # endif
  418. # define NO_SYSLOG
  419. # define _setmode setmode
  420. # define _kbhit kbhit
  421. # define _O_TEXT O_TEXT
  422. # define _O_BINARY O_BINARY
  423. # define OPENSSL_CONF "openssl.cnf"
  424. # define SSLEAY_CONF OPENSSL_CONF
  425. # define RFILE ".rnd"
  426. # define LIST_SEPARATOR_CHAR ';'
  427. # define EXIT(n) { if (n) printf("ERROR: %d\n", (int)n); exit(n); }
  428. # else
  429. /* !defined VMS */
  430. # ifdef OPENSSL_SYS_MPE
  431. # define NO_SYS_PARAM_H
  432. # endif
  433. # ifdef OPENSSL_UNISTD
  434. # include OPENSSL_UNISTD
  435. # else
  436. # include <unistd.h>
  437. # endif
  438. # ifndef NO_SYS_TYPES_H
  439. # include <sys/types.h>
  440. # endif
  441. # if defined(NeXT) || defined(OPENSSL_SYS_NEWS4)
  442. # define pid_t int /* pid_t is missing on NEXTSTEP/OPENSTEP
  443. * (unless when compiling with
  444. * -D_POSIX_SOURCE, which doesn't work for
  445. * us) */
  446. # endif
  447. # ifdef OPENSSL_SYS_NEWS4 /* setvbuf is missing on mips-sony-bsd */
  448. # define setvbuf(a, b, c, d) setbuffer((a), (b), (d))
  449. typedef unsigned long clock_t;
  450. # endif
  451. # ifdef OPENSSL_SYS_WIN32_CYGWIN
  452. # include <io.h>
  453. # include <fcntl.h>
  454. # endif
  455. # define OPENSSL_CONF "openssl.cnf"
  456. # define SSLEAY_CONF OPENSSL_CONF
  457. # define RFILE ".rnd"
  458. # define LIST_SEPARATOR_CHAR ':'
  459. # define NUL_DEV "/dev/null"
  460. # define EXIT(n) exit(n)
  461. # endif
  462. # define SSLeay_getpid() getpid()
  463. # endif
  464. /*************/
  465. # ifdef USE_SOCKETS
  466. # if defined(WINDOWS) || defined(MSDOS)
  467. /* windows world */
  468. # ifdef OPENSSL_NO_SOCK
  469. # define SSLeay_Write(a,b,c) (-1)
  470. # define SSLeay_Read(a,b,c) (-1)
  471. # define SHUTDOWN(fd) close(fd)
  472. # define SHUTDOWN2(fd) close(fd)
  473. # elif !defined(__DJGPP__)
  474. # if defined(_WIN32_WCE) && _WIN32_WCE<410
  475. # define getservbyname _masked_declaration_getservbyname
  476. # endif
  477. # if !defined(IPPROTO_IP)
  478. /* winsock[2].h was included already? */
  479. # include <winsock.h>
  480. # endif
  481. # ifdef getservbyname
  482. # undef getservbyname
  483. /* this is used to be wcecompat/include/winsock_extras.h */
  484. struct servent *PASCAL getservbyname(const char *, const char *);
  485. # endif
  486. # ifdef _WIN64
  487. /*
  488. * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
  489. * the value constitutes an index in per-process table of limited size
  490. * and not a real pointer.
  491. */
  492. # define socket(d,t,p) ((int)socket(d,t,p))
  493. # define accept(s,f,l) ((int)accept(s,f,l))
  494. # endif
  495. # define SSLeay_Write(a,b,c) send((a),(b),(c),0)
  496. # define SSLeay_Read(a,b,c) recv((a),(b),(c),0)
  497. # define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); }
  498. # define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); }
  499. # else
  500. # define SSLeay_Write(a,b,c) write_s(a,b,c,0)
  501. # define SSLeay_Read(a,b,c) read_s(a,b,c)
  502. # define SHUTDOWN(fd) close_s(fd)
  503. # define SHUTDOWN2(fd) close_s(fd)
  504. # endif
  505. # elif defined(MAC_OS_pre_X)
  506. # include "MacSocket.h"
  507. # define SSLeay_Write(a,b,c) MacSocket_send((a),(b),(c))
  508. # define SSLeay_Read(a,b,c) MacSocket_recv((a),(b),(c),true)
  509. # define SHUTDOWN(fd) MacSocket_close(fd)
  510. # define SHUTDOWN2(fd) MacSocket_close(fd)
  511. # elif defined(OPENSSL_SYS_NETWARE)
  512. /*
  513. * NetWare uses the WinSock2 interfaces by default, but can be
  514. * configured for BSD
  515. */
  516. # if defined(NETWARE_BSDSOCK)
  517. # include <sys/socket.h>
  518. # include <netinet/in.h>
  519. # include <sys/time.h>
  520. # if defined(NETWARE_CLIB)
  521. # include <sys/bsdskt.h>
  522. # else
  523. # include <sys/select.h>
  524. # endif
  525. # define INVALID_SOCKET (int)(~0)
  526. # else
  527. # include <novsock2.h>
  528. # endif
  529. # define SSLeay_Write(a,b,c) send((a),(b),(c),0)
  530. # define SSLeay_Read(a,b,c) recv((a),(b),(c),0)
  531. # define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); }
  532. # define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); }
  533. # else
  534. # ifndef NO_SYS_PARAM_H
  535. # include <sys/param.h>
  536. # endif
  537. # ifdef OPENSSL_SYS_VXWORKS
  538. # include <time.h>
  539. # elif !defined(OPENSSL_SYS_MPE)
  540. # include <sys/time.h> /* Needed under linux for FD_XXX */
  541. # endif
  542. # include <netdb.h>
  543. # if defined(OPENSSL_SYS_VMS_NODECC)
  544. # include <socket.h>
  545. # include <in.h>
  546. # include <inet.h>
  547. # else
  548. # include <sys/socket.h>
  549. # ifdef FILIO_H
  550. # include <sys/filio.h> /* Added for FIONBIO under unixware */
  551. # endif
  552. # include <netinet/in.h>
  553. # if !defined(OPENSSL_SYS_BEOS_R5)
  554. # include <arpa/inet.h>
  555. # endif
  556. # endif
  557. # if defined(NeXT) || defined(_NEXT_SOURCE)
  558. # include <sys/fcntl.h>
  559. # include <sys/types.h>
  560. # endif
  561. # ifdef OPENSSL_SYS_AIX
  562. # include <sys/select.h>
  563. # endif
  564. # ifdef __QNX__
  565. # include <sys/select.h>
  566. # endif
  567. # if defined(__sun) || defined(sun)
  568. # include <sys/filio.h>
  569. # else
  570. # ifndef VMS
  571. # include <sys/ioctl.h>
  572. # else
  573. /* ioctl is only in VMS > 7.0 and when socketshr is not used */
  574. # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
  575. # include <sys/ioctl.h>
  576. # endif
  577. # endif
  578. # endif
  579. # ifdef VMS
  580. # include <unixio.h>
  581. # if defined(TCPIP_TYPE_SOCKETSHR)
  582. # include <socketshr.h>
  583. # endif
  584. # endif
  585. # define SSLeay_Read(a,b,c) read((a),(b),(c))
  586. # define SSLeay_Write(a,b,c) write((a),(b),(c))
  587. # define SHUTDOWN(fd) { shutdown((fd),0); closesocket((fd)); }
  588. # define SHUTDOWN2(fd) { shutdown((fd),2); closesocket((fd)); }
  589. # ifndef INVALID_SOCKET
  590. # define INVALID_SOCKET (-1)
  591. # endif /* INVALID_SOCKET */
  592. # endif
  593. /*
  594. * Some IPv6 implementations are broken, disable them in known bad versions.
  595. */
  596. # if !defined(OPENSSL_USE_IPV6)
  597. # if defined(AF_INET6) && !defined(OPENSSL_SYS_BEOS_BONE) && !defined(NETWARE_CLIB)
  598. # define OPENSSL_USE_IPV6 1
  599. # else
  600. # define OPENSSL_USE_IPV6 0
  601. # endif
  602. # endif
  603. # endif
  604. # if (defined(__sun) || defined(sun)) && !defined(__svr4__) && !defined(__SVR4)
  605. /* include headers first, so our defines don't break it */
  606. # include <stdlib.h>
  607. # include <string.h>
  608. /* bcopy can handle overlapping moves according to SunOS 4.1.4 manpage */
  609. # define memmove(s1,s2,n) bcopy((s2),(s1),(n))
  610. # define strtoul(s,e,b) ((unsigned long int)strtol((s),(e),(b)))
  611. extern char *sys_errlist[];
  612. extern int sys_nerr;
  613. # define strerror(errnum) \
  614. (((errnum)<0 || (errnum)>=sys_nerr) ? NULL : sys_errlist[errnum])
  615. /* Being signed SunOS 4.x memcpy breaks ASN1_OBJECT table lookup */
  616. # include "crypto/o_str.h"
  617. # define memcmp OPENSSL_memcmp
  618. # endif
  619. # ifndef OPENSSL_EXIT
  620. # if defined(MONOLITH) && !defined(OPENSSL_C)
  621. # define OPENSSL_EXIT(n) return(n)
  622. # else
  623. # define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
  624. # endif
  625. # endif
  626. /***********************************************/
  627. # define DG_GCC_BUG /* gcc < 2.6.3 on DGUX */
  628. # ifdef sgi
  629. # define IRIX_CC_BUG /* all version of IRIX I've tested (4.* 5.*) */
  630. # endif
  631. # ifdef OPENSSL_SYS_SNI
  632. # define IRIX_CC_BUG /* CDS++ up to V2.0Bsomething suffered from
  633. * the same bug. */
  634. # endif
  635. # if defined(OPENSSL_SYS_WINDOWS)
  636. # define strcasecmp _stricmp
  637. # define strncasecmp _strnicmp
  638. # elif defined(OPENSSL_SYS_VMS)
  639. /* VMS below version 7.0 doesn't have strcasecmp() */
  640. # include "o_str.h"
  641. # define strcasecmp OPENSSL_strcasecmp
  642. # define strncasecmp OPENSSL_strncasecmp
  643. # define OPENSSL_IMPLEMENTS_strncasecmp
  644. # elif defined(OPENSSL_SYS_OS2) && defined(__EMX__)
  645. # define strcasecmp stricmp
  646. # define strncasecmp strnicmp
  647. # elif defined(OPENSSL_SYS_NETWARE)
  648. # include <string.h>
  649. # if defined(NETWARE_CLIB)
  650. # define strcasecmp stricmp
  651. # define strncasecmp strnicmp
  652. # endif /* NETWARE_CLIB */
  653. # endif
  654. # if defined(OPENSSL_SYS_OS2) && defined(__EMX__)
  655. # include <io.h>
  656. # include <fcntl.h>
  657. # define NO_SYSLOG
  658. # endif
  659. /* vxworks */
  660. # if defined(OPENSSL_SYS_VXWORKS)
  661. # include <ioLib.h>
  662. # include <tickLib.h>
  663. # include <sysLib.h>
  664. # define TTY_STRUCT int
  665. # define sleep(a) taskDelay((a) * sysClkRateGet())
  666. # include <vxWorks.h>
  667. # include <sockLib.h>
  668. # include <taskLib.h>
  669. # define getpid taskIdSelf
  670. /*
  671. * NOTE: these are implemented by helpers in database app! if the database is
  672. * not linked, we need to implement them elswhere
  673. */
  674. struct hostent *gethostbyname(const char *name);
  675. struct hostent *gethostbyaddr(const char *addr, int length, int type);
  676. struct servent *getservbyname(const char *name, const char *proto);
  677. # endif
  678. /* end vxworks */
  679. /* beos */
  680. # if defined(OPENSSL_SYS_BEOS_R5)
  681. # define SO_ERROR 0
  682. # define NO_SYS_UN
  683. # define IPPROTO_IP 0
  684. # include <OS.h>
  685. # endif
  686. # if !defined(inline) && !defined(__cplusplus)
  687. # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
  688. /* do nothing, inline works */
  689. # elif defined(__GNUC__) && __GNUC__>=2
  690. # define inline __inline__
  691. # elif defined(_MSC_VER)
  692. /*
  693. * Visual Studio: inline is available in C++ only, however
  694. * __inline is available for C, see
  695. * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
  696. */
  697. # define inline __inline
  698. # else
  699. # define inline
  700. # endif
  701. # endif
  702. #ifdef __cplusplus
  703. }
  704. #endif
  705. #endif