e_os.h 25 KB

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