Fix to build better with DJGPP.
authorRichard Levitte <levitte@openssl.org>
Thu, 14 Nov 2002 11:22:46 +0000 (11:22 +0000)
committerRichard Levitte <levitte@openssl.org>
Thu, 14 Nov 2002 11:22:46 +0000 (11:22 +0000)
PR: 338

Here's the description, submitted by Gisle Vanem <giva@bgnett.no>:

1. sock_init() renamed to ssl_sock_init() in ./apps/s_socket.c due
   to name-clash with Watt-32.

2. rand() renamed to Rand() in ./crypto/bn/divtest.c due to name-clash
   with <stdlib.h>

3. Added calls to dbug_init()/sock_init() in some demo programs.

4. Changed cflags/lflags in configure. Watt-32 install root now taken
   from $WATT_ROOT.

Configure
apps/s_client.c
apps/s_server.c
apps/s_socket.c
crypto/bio/b_sock.c
crypto/bio/bss_log.c
crypto/bio/bss_sock.c
crypto/bn/divtest.c
demos/bio/saccept.c
demos/bio/sconnect.c
e_os.h

index a6021dfd3f95f3c39dba1c09f9951e11784cc315..a26bc555de2a640f973f4c1d5ed60bbd8ccd24b1 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -523,7 +523,7 @@ my %table=(
 "Cygwin", "gcc:-DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall:::CYGWIN32::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_out_asm}:win32:cygwin-shared:::.dll",
 
 # DJGPP
-"DJGPP", "gcc:-I/dev/env/DJDIR/watt32/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall:::MSDOS:-L/dev/env/DJDIR/watt32/lib -lwatt:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}::::::::::",
+"DJGPP", "gcc:-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall:::MSDOS:-L/dev/env/WATT_ROOT/lib -lwatt:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}::::::::::",
 
 # Ultrix from Bernhard Simon <simon@zid.tuwien.ac.at>
 "ultrix-cc","cc:-std1 -O -Olimit 1000 -DL_ENDIAN::(unknown):::::::",
index fa881e13054cabe370a4815d335ddd47d9a8fcce..1b670aa4ee4acf9dcfaf7018afa3c7b776730042 100644 (file)
@@ -746,8 +746,8 @@ re_start:
                                goto shut;
                                }
                        }
-#ifdef OPENSSL_SYS_WINDOWS
-               /* Assume Windows can always write */
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
+               /* Assume Windows/DOS can always write */
                else if (!ssl_pending && write_tty)
 #else
                else if (!ssl_pending && FD_ISSET(fileno(stdout),&writefds))
index c936d6605a041635d264c1915864f2ba6e284475..4ba3bcefb0f2923da93e0386144a0ea968f244e6 100644 (file)
@@ -1395,7 +1395,7 @@ static int www_body(char *hostname, int s, unsigned char *context)
                        else
                                {
                                BIO_printf(bio_s_out,"read R BLOCK\n");
-#ifndef OPENSSL_SYS_MSDOS
+#if !defined(OPENSSL_SYS_MSDOS) && !defined(__DJGPP__)
                                sleep(1);
 #endif
                                continue;
index 01a980c96d2345f7609d0d91e7bebc4f56df3c91..ed15ce0c1ddcb3867032a8bbfda4b710cb669e2a 100644 (file)
@@ -83,9 +83,9 @@ typedef unsigned int u_int;
 
 static struct hostent *GetHostByName(char *name);
 #ifdef OPENSSL_SYS_WINDOWS
-static void sock_cleanup(void);
+static void ssl_sock_cleanup(void);
 #endif
-static int sock_init(void);
+static int ssl_sock_init(void);
 static int init_client_ip(int *sock,unsigned char ip[4], int port);
 static int init_server(int *sock, int port);
 static int init_server_long(int *sock, int port,char *ip);
@@ -118,7 +118,7 @@ static LONG FAR PASCAL topHookProc(HWND hwnd, UINT message, WPARAM wParam,
                case WM_DESTROY:
                case WM_CLOSE:
                        SetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopWndProc);
-                       sock_cleanup();
+                       ssl_sock_cleanup();
                        break;
                        }
                }
@@ -135,7 +135,7 @@ static BOOL CALLBACK enumproc(HWND hwnd,LPARAM lParam)
 #endif /* OPENSSL_SYS_WINDOWS */
 
 #ifdef OPENSSL_SYS_WINDOWS
-static void sock_cleanup(void)
+static void ssl_sock_cleanup(void)
        {
        if (wsa_init_done)
                {
@@ -146,15 +146,21 @@ static void sock_cleanup(void)
        }
 #endif
 
-static int sock_init(void)
+static int ssl_sock_init(void)
        {
-#ifdef OPENSSL_SYS_WINDOWS
+#ifdef WATT32
+       extern int _watt_do_exit;
+       _watt_do_exit = 0;
+       dbug_init();
+       if (sock_init())
+               return (0);
+#elif defined(OPENSSL_SYS_WINDOWS)
        if (!wsa_init_done)
                {
                int err;
          
 #ifdef SIGINT
-               signal(SIGINT,(void (*)(int))sock_cleanup);
+               signal(SIGINT,(void (*)(int))ssl_sock_cleanup);
 #endif
                wsa_init_done=1;
                memset(&wsa_state,0,sizeof(wsa_state));
@@ -196,7 +202,7 @@ static int init_client_ip(int *sock, unsigned char ip[4], int port)
        struct sockaddr_in them;
        int s,i;
 
-       if (!sock_init()) return(0);
+       if (!ssl_sock_init()) return(0);
 
        memset((char *)&them,0,sizeof(them));
        them.sin_family=AF_INET;
@@ -261,7 +267,7 @@ static int init_server_long(int *sock, int port, char *ip)
        struct sockaddr_in server;
        int s= -1,i;
 
-       if (!sock_init()) return(0);
+       if (!ssl_sock_init()) return(0);
 
        memset((char *)&server,0,sizeof(server));
        server.sin_family=AF_INET;
@@ -318,7 +324,7 @@ static int do_accept(int acc_sock, int *sock, char **host)
        int len;
 /*     struct linger ling; */
 
-       if (!sock_init()) return(0);
+       if (!ssl_sock_init()) return(0);
 
 #ifndef OPENSSL_SYS_WINDOWS
 redoit:
@@ -448,7 +454,7 @@ static int host_ip(char *str, unsigned char ip[4])
                { /* do a gethostbyname */
                struct hostent *he;
 
-               if (!sock_init()) return(0);
+               if (!ssl_sock_init()) return(0);
 
                he=GetHostByName(str);
                if (he == NULL)
index 3188bcc69c933363944e6640a7ee220b07f3723f..a7da2581014275ce32421a11dd3ce0ddb2ee3732 100644 (file)
@@ -467,6 +467,12 @@ int BIO_sock_init(void)
                        }
                }
 #endif /* OPENSSL_SYS_WINDOWS */
+#ifdef WATT32
+       extern int _watt_do_exit;
+       _watt_do_exit = 0;    /* don't make sock_init() call exit() */
+       if (sock_init())
+               return (-1);
+#endif
        return(1);
        }
 
index 901b64f3ae5913b2de765e05224f5371128b76ff..534181267216418ee238c17ef41e9192bedc7ab3 100644 (file)
@@ -77,7 +77,7 @@
 #  include <starlet.h>
 #elif defined(__ultrix)
 #  include <sys/syslog.h>
-#elif !defined(MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG) /* Unix */
+#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG)
 #  include <syslog.h>
 #endif
 
@@ -373,11 +373,15 @@ static void xcloselog(BIO* bp)
 {
 }
 
-#else /* Unix */
+#else /* Unix/Watt32 */
 
 static void xopenlog(BIO* bp, char* name, int level)
 {
+#ifdef WATT32   /* djgpp/DOS */
+       openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level);
+#else
        openlog(name, LOG_PID|LOG_CONS, level);
+#endif
 }
 
 static void xsyslog(BIO *bp, int priority, const char *string)
index fdabd16d7eaab7e97435ee4063b6fd72401a2a96..2c1c405ec7e8f5ffe1182e33168a3fb068197075 100644 (file)
 #include "cryptlib.h"
 #include <openssl/bio.h>
 
+#ifdef WATT32
+#define sock_write SockWrite  /* Watt-32 uses same names */
+#define sock_read  SockRead
+#define sock_puts  SockPuts
+#endif
+
 static int sock_write(BIO *h, const char *buf, int num);
 static int sock_read(BIO *h, char *buf, int size);
 static int sock_puts(BIO *h, const char *str);
index 13ba86e3c4e1433b8a2320a536d2616d84212cab..d3fc688f33572cfae548fc180c38488ef2c4faee 100644 (file)
@@ -1,7 +1,7 @@
 #include <openssl/bn.h>
 #include <openssl/rand.h>
 
-static int rand(n)
+static int Rand(n)
 {
     unsigned char x[2];
     RAND_pseudo_bytes(x,2);
@@ -26,8 +26,8 @@ main()
     BN_CTX *ctx=BN_CTX_new();
 
     for(;;) {
-       BN_pseudo_rand(a,rand(),0,0);
-       BN_pseudo_rand(b,rand(),0,0);
+       BN_pseudo_rand(a,Rand(),0,0);
+       BN_pseudo_rand(b,Rand(),0,0);
        if (BN_is_zero(b)) continue;
 
        BN_RECP_CTX_set(recp,b,ctx);
index 933d6699ee344940c68cdbc6fa6cc39dc14efac4..40cd4daad2939d2768d4048444b09cf3bd3e4482 100644 (file)
@@ -45,6 +45,11 @@ char *argv[];
 
        SSL_load_error_strings();
 
+#ifdef WATT32
+       dbug_init();
+       sock_init();
+#endif
+
        /* Add ciphers and message digests */
        OpenSSL_add_ssl_algorithms();
 
index 87b380b258cb8f5b0c3574ec5aa07ac37a3fde0b..880344eb78453b80b3c87a5c357b2b1114a82d77 100644 (file)
@@ -32,6 +32,11 @@ char *argv[];
        else
                host=argv[1];
 
+#ifdef WATT32
+       dbug_init();
+       sock_init();
+#endif
+
        /* Lets get nice error messages */
        SSL_load_error_strings();
 
diff --git a/e_os.h b/e_os.h
index 6d326e54e3e01d3dffe6d65ffe589885e9605cf0..2455f993861f9d13e29c2b6b51bdb4e3e47fa9f4 100644 (file)
--- a/e_os.h
+++ b/e_os.h
@@ -154,6 +154,13 @@ extern "C" {
 #define readsocket(s,b,n)      recv((s),(b),(n),0)
 #define writesocket(s,b,n)     send((s),(b),(n),0)
 #define EADDRINUSE             WSAEADDRINUSE
+#elif defined(__DJGPP__)
+#define WATT32
+#define get_last_socket_error()        errno
+#define clear_socket_error()   errno=0
+#define closesocket(s)         close_s(s)
+#define readsocket(s,b,n)      read_s(s,b,n)
+#define writesocket(s,b,n)     send(s,b,n,0)
 #elif defined(MAC_OS_pre_X)
 #define get_last_socket_error()        errno
 #define clear_socket_error()   errno=0
@@ -207,7 +214,7 @@ extern "C" {
 #    define S_IFMT     _S_IFMT
 #  endif
 
-#  if !defined(WINNT)
+#  if !defined(WINNT) && !defined(__DJGPP__)
 #    define NO_SYSLOG
 #  endif
 #  define NO_DIRENT
@@ -344,7 +351,7 @@ extern "C" {
 /*************/
 
 #ifdef USE_SOCKETS
-#  if (defined(WINDOWS) || defined(MSDOS)) && !defined(__DJGPP__)
+#  if defined(WINDOWS) || defined(MSDOS)
       /* windows world */
 
 #    ifdef OPENSSL_NO_SOCK
@@ -352,13 +359,18 @@ extern "C" {
 #      define SSLeay_Read(a,b,c)       (-1)
 #      define SHUTDOWN(fd)             close(fd)
 #      define SHUTDOWN2(fd)            close(fd)
-#    else
+#    elif !defined(__DJGPP__)
 #      include <winsock.h>
 extern HINSTANCE _hInstance;
 #      define SSLeay_Write(a,b,c)      send((a),(b),(c),0)
 #      define SSLeay_Read(a,b,c)       recv((a),(b),(c),0)
 #      define SHUTDOWN(fd)             { shutdown((fd),0); closesocket(fd); }
 #      define SHUTDOWN2(fd)            { shutdown((fd),2); closesocket(fd); }
+#    else
+#      define SSLeay_Write(a,b,c)      write_s(a,b,c,0)
+#      define SSLeay_Read(a,b,c)       read_s(a,b,c)
+#      define SHUTDOWN(fd)             close_s(fd)
+#      define SHUTDOWN2(fd)            close_s(fd)
 #    endif
 
 #  elif defined(MAC_OS_pre_X)