Fix mkerr.pl to find functions returning function pointers (thanks Ulf!)
[openssl.git] / crypto / cryptlib.c
index 12cf0733ec9a15a51e9b2e1505a612a175993bf7..3169b26b32d9bd0381ac026b8937a316a8d427fc 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/cryptlib.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
 #include <stdio.h>
 #include <string.h>
 #include "cryptlib.h"
-#include "crypto.h"
+#include <openssl/crypto.h>
 #include "date.h"
 
+#if defined(WIN32) || defined(WIN16)
+static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
+#endif
+
 /* real #defines in crypto.h, keep these upto date */
-static char* lock_names[CRYPTO_NUM_LOCKS] =
+static const char* lock_names[CRYPTO_NUM_LOCKS] =
        {
        "<<ERROR>>",
        "err",
@@ -83,15 +87,18 @@ static char* lock_names[CRYPTO_NUM_LOCKS] =
        "ssl",
        "rand",
        "debug_malloc",
-       "bio_gethostbyname",
        "BIO",
+       "bio_gethostbyname",
+       "RSA_blinding",
        };
 
+static STACK *app_locks=NULL;
+
 #ifndef NOPROTO
 static void (MS_FAR *locking_callback)(int mode,int type,
-       char *file,int line)=NULL;
+       const char *file,int line)=NULL;
 static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
-       int type,char *file,int line)=NULL;
+       int type,const char *file,int line)=NULL;
 static unsigned long (MS_FAR *id_callback)(void)=NULL;
 #else
 static void (MS_FAR *locking_callback)()=NULL;
@@ -99,24 +106,54 @@ static int (MS_FAR *add_lock_callback)()=NULL;
 static unsigned long (MS_FAR *id_callback)()=NULL;
 #endif
 
-void (*CRYPTO_get_locking_callback(P_V))(P_I_I_P_I)
+int CRYPTO_get_new_lockid(char *name)
+       {
+       char *str;
+       int i;
+
+       /* A hack to make Visual C++ 5.0 work correctly when linking as
+        * a DLL using /MT. Without this, the application cannot use
+        * and floating point printf's.
+        * It also seems to be needed for Visual C 1.5 (win16) */
+#if defined(WIN32) || defined(WIN16)
+       SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
+#endif
+
+       if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
+               {
+               CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
+               return(0);
+               }
+       if ((str=BUF_strdup(name)) == NULL)
+               return(0);
+       i=sk_push(app_locks,str);
+       if (!i)
+               Free(str);
+       else
+               i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
+       return(i);
+       }
+
+void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
+               int line)
        {
        return(locking_callback);
        }
 
-int (*CRYPTO_get_add_lock_callback(P_V))(P_IP_I_I_P_I)
+int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
+                                         const char *file,int line)
        {
        return(add_lock_callback);
        }
 
-void CRYPTO_set_locking_callback(func)
-void (*func)(P_I_I_P_I);
+void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
+                                             const char *file,int line))
        {
        locking_callback=func;
        }
 
-void CRYPTO_set_add_lock_callback(func)
-int (*func)(P_IP_I_I_P_I);
+void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
+                                             const char *file,int line))
        {
        add_lock_callback=func;
        }
@@ -126,13 +163,12 @@ unsigned long (*CRYPTO_get_id_callback(P_V))(P_V)
        return(id_callback);
        }
 
-void CRYPTO_set_id_callback(func)
-unsigned long (*func)(P_V);
+void CRYPTO_set_id_callback(func) unsigned long (*func)(P_V);
        {
        id_callback=func;
        }
 
-unsigned long CRYPTO_thread_id()
+unsigned long CRYPTO_thread_id(void)
        {
        unsigned long ret=0;
 
@@ -153,11 +189,7 @@ unsigned long CRYPTO_thread_id()
        return(ret);
        }
 
-void CRYPTO_lock(mode,type,file,line)
-int mode;
-int type;
-char *file;
-int line;
+void CRYPTO_lock(int mode, int type, const char *file, int line)
        {
 #ifdef LOCK_DEBUG
                {
@@ -186,12 +218,8 @@ int line;
                locking_callback(mode,type,file,line);
        }
 
-int CRYPTO_add_lock(pointer,amount,type,file,line)
-int *pointer;
-int amount;
-int type;
-char *file;
-int line;
+int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
+            int line)
        {
        int ret;
 
@@ -229,12 +257,16 @@ int line;
        return(ret);
        }
 
-char *CRYPTO_get_lock_name(type)
-int type;
+const char *CRYPTO_get_lock_name(int type)
        {
-       if ((type < 0) || (type >= CRYPTO_NUM_LOCKS))
+       if (type < 0)
                return("ERROR");
-       return(lock_names[type]);
+       else if (type < CRYPTO_NUM_LOCKS)
+               return(lock_names[type]);
+       else if (type-CRYPTO_NUM_LOCKS >= sk_num(app_locks))
+               return("ERROR");
+       else
+               return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
        }
 
 #ifdef _DLL
@@ -243,10 +275,8 @@ int type;
 /* All we really need to do is remove the 'error' state when a thread
  * detaches */
 
-BOOL WINAPI DLLEntryPoint(hinstDLL,fdwReason,lpvReserved)
-HINSTANCE hinstDLL;
-DWORD fdwReason;
-LPVOID lpvReserved;
+BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason,
+            LPVOID lpvReserved)
        {
        switch(fdwReason)
                {