This _WIN32-specific patch makes it possible to "wrap" OpenSSL in another
authorAndy Polyakov <appro@openssl.org>
Mon, 22 Dec 2008 13:54:12 +0000 (13:54 +0000)
committerAndy Polyakov <appro@openssl.org>
Mon, 22 Dec 2008 13:54:12 +0000 (13:54 +0000)
.DLL, in particular static build. The issue has been discussed in RT#1230
and later on openssl-dev, and mutually exclusive approaches were suggested.
This completes compromise solution suggested in RT#1230.
PR: 1230

crypto/bio/bss_file.c
crypto/des/enc_read.c
crypto/des/enc_writ.c
crypto/ocsp/ocsp_ht.c
crypto/rand/randfile.c
crypto/ui/ui_openssl.c
crypto/x509/by_dir.c
e_os.h
engines/e_aep.c

index 545c1b2bdd4ad1ce70af4cf1d12b7bc6224f0c62..480208a31592adffb7d3ea37f4a53129814cd82b 100644 (file)
@@ -279,7 +279,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
 #endif
                {
 #if defined(OPENSSL_SYS_WINDOWS)
-               int fd = fileno((FILE*)ptr);
+               int fd = _fileno((FILE*)ptr);
                if (num & BIO_FP_TEXT)
                        _setmode(fd,_O_TEXT);
                else
index b86620f56823b3601a8062018d6600b420d09186..372ef667b83d92860dad45eda9a907714ec01c8f 100644 (file)
@@ -150,7 +150,11 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
        /* first - get the length */
        while (net_num < HDRSIZE) 
                {
+#ifndef _WIN32
                i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
+#else
+               i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
+#endif
 #ifdef EINTR
                if ((i == -1) && (errno == EINTR)) continue;
 #endif
index 6e25b6d4f048e32e5cd123f065a9bd46c354fbea..2353ac1e892fd3310b68450293ad030cfc70147e 100644 (file)
@@ -156,7 +156,11 @@ int DES_enc_write(int fd, const void *_buf, int len,
                {
                /* eay 26/08/92 I was not doing writing from where we
                 * got up to. */
+#ifndef _WIN32
                i=write(fd,(void *)&(outbuf[j]),outnum-j);
+#else
+               i=_write(fd,(void *)&(outbuf[j]),outnum-j);
+#endif
                if (i == -1)
                        {
 #ifdef EINTR
index dd25f5c85fbfeb8c5b169b08fb95237e7718c56a..38602fae4aad2a896e0a83917047611c458fa8d0 100644 (file)
  *
  */
 
-#include <openssl/asn1.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include "e_os.h"
+#include <openssl/asn1.h>
 #include <openssl/ocsp.h>
 #include <openssl/err.h>
 #include <openssl/buffer.h>
index c4e616077923a3fca2f6e5a881972365b8f0ae8b..4723feecaf30ff7a3f60c4a24618d31c3f132aca 100644 (file)
 # include <sys/stat.h>
 #endif
 
+#ifdef _WIN32
+#define stat   _stat
+#define chmod  _chmod
+#define open   _open
+#define fdopen _fdopen
+#endif
+
 #undef BUFSIZE
 #define BUFSIZE        1024
 #define RAND_DATA 1024
index 8eabb850ff9c70516b63e9113916d2f360acbbed..1c2dcc406e66237b21f3ce279bc4eea64c51b42c 100644 (file)
@@ -677,6 +677,8 @@ static int noecho_fgets(char *buf, int size, FILE *tty)
                size--;
 #ifdef WIN16TTY
                i=_inchar();
+#elif defined(_WIN32)
+               i=_getch();
 #else
                i=getch();
 #endif
index b355de9b1c27756296735150d98511784da9d840..170cd89608f9646ee9a2b291b512cedeebff27b3 100644 (file)
@@ -392,6 +392,9 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
                                        postfix,k);
                                }
 #ifndef OPENSSL_NO_POSIX_IO
+#ifdef _WIN32
+#define stat _stat
+#endif
                        {
                        struct stat st;
                        if (stat(b->data,&st) < 0)
diff --git a/e_os.h b/e_os.h
index 01d7963ecc93019a7462436bd2519e752ac0c63d..c6c6082c83feb2da2499ca3972492af6fdbf7fd4 100644 (file)
--- a/e_os.h
+++ b/e_os.h
@@ -285,6 +285,7 @@ extern "C" {
        /* yes, they have to be #included prior <windows.h> */
 #    endif
 #    include <windows.h>
+#    include <stdio.h>
 #    include <stddef.h>
 #    include <errno.h>
 #    include <string.h>
@@ -300,13 +301,38 @@ static unsigned int _strlen31(const char *str)
 #    endif
 #    include <malloc.h>
 #    if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
-       /* compensate for bug is VC6 ctype.h */
+       /* compensate for bug in VC6 ctype.h */
 #      undef isspace
 #      undef isdigit
 #      undef isalnum
 #      undef isupper
 #      undef isxdigit
 #    endif
+#    if defined(_MSC_VER) && !defined(_DLL) && defined(stdin)
+#      if _MSC_VER>=1300
+#        undef stdin
+#        undef stdout
+#        undef stderr
+         FILE *__iob_func();
+#        define stdin  (&__iob_func()[0])
+#        define stdout (&__iob_func()[1])
+#        define stderr (&__iob_func()[2])
+#      elif defined(I_CAN_LIVE_WITH_LNK4049)
+#        undef stdin
+#        undef stdout
+#        undef stderr
+         /* pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
+          * or in other words with /MD. Declaring implicit import, i.e.
+          * with _imp_ prefix, works correctly with all compiler options,
+         * but without /MD results in LINK warning LNK4049:
+         * 'locally defined symbol "__iob" imported'.
+          */
+         extern FILE *_imp___iob;
+#        define stdin  (&_imp___iob[0])
+#        define stdout (&_imp___iob[1])
+#        define stderr (&_imp___iob[2])
+#      endif
+#    endif
 #  endif
 #  include <io.h>
 #  include <fcntl.h>
index a91a39f0183ba3f3b9ce0d56b01d3df8ab8a5c77..742b4f9b186dea01a64567568781fa4dec93aecb 100644 (file)
@@ -867,10 +867,12 @@ static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection)
 
        CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
 
-#ifndef NETWARE_CLIB
-       curr_pid = getpid();
-#else
+#ifdef NETWARE_CLIB
        curr_pid = GetThreadID();
+#elif defined(_WIN32)
+       curr_pid = _getpid();
+#else
+       curr_pid = getpid();
 #endif
 
        /*Check if this is the first time this is being called from the current