typo
[openssl.git] / crypto / err / err.c
index 81822b4aeac46eb18b033d06d69507b96f5d397d..75a69c3e406a16de5d6da6d5febdc665428e7d9d 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/bio.h>
 #include <openssl/err.h>
 
+static void err_load_strings(int lib, ERR_STRING_DATA *str);
+
 static void ERR_STATE_free(ERR_STATE *s);
 #ifndef OPENSSL_NO_ERR
 static ERR_STRING_DATA ERR_str_libraries[]=
@@ -275,8 +277,10 @@ static int int_err_library_number=ERR_LIB_USER;
  * the defaults. */
 static void err_fns_check(void)
        {
+       if (err_fns) return;
+       
        CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if(!err_fns)
+       if (!err_fns)
                err_fns = &err_defaults;
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        }
@@ -334,6 +338,7 @@ static LHASH *int_err_get(void)
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        return(toret);
        }
+
 static void int_err_del(void)
        {
        CRYPTO_w_lock(CRYPTO_LOCK_ERR);
@@ -345,6 +350,7 @@ static void int_err_del(void)
                }
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        }
+
 static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
        {
        ERR_STRING_DATA *p;
@@ -358,6 +364,7 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
        CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
        return p;
        }
+
 static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
        {
        ERR_STRING_DATA *p;
@@ -366,11 +373,12 @@ static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
        hash = ERRFN(err_get)();
        if(!hash)
                return NULL;
-       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
        p = (ERR_STRING_DATA *)lh_insert(hash, d);
-       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        return p;
        }
+
 static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
        {
        ERR_STRING_DATA *p;
@@ -379,11 +387,12 @@ static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
        hash = ERRFN(err_get)();
        if(!hash)
                return NULL;
-       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
        p = (ERR_STRING_DATA *)lh_delete(hash, d);
-       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        return p;
        }
+
 static LHASH *int_thread_get(void)
        {
        LHASH *toret = NULL;
@@ -398,6 +407,7 @@ static LHASH *int_thread_get(void)
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        return(toret);
        }
+
 static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
        {
        ERR_STATE *p;
@@ -411,6 +421,7 @@ static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
        CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
        return p;
        }
+
 static ERR_STATE *int_thread_set_item(ERR_STATE *d)
        {
        ERR_STATE *p;
@@ -419,11 +430,12 @@ static ERR_STATE *int_thread_set_item(ERR_STATE *d)
        hash = ERRFN(thread_get)();
        if(!hash)
                return NULL;
-       CRYPTO_r_lock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_lock(CRYPTO_LOCK_ERR);
        p = (ERR_STATE *)lh_insert(hash, d);
-       CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
+       CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        return p;
        }
+
 static void int_thread_del_item(const ERR_STATE *d)
        {
        ERR_STATE *p;
@@ -445,6 +457,7 @@ static void int_thread_del_item(const ERR_STATE *d)
        if(p)
                ERR_STATE_free(p);
        }
+
 static int int_err_get_next_lib(void)
        {
        int toret;
@@ -473,6 +486,9 @@ static void build_SYS_str_reasons()
        /* OPENSSL_malloc cannot be used here, use static storage instead */
        static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
        int i;
+       static int init = 1;
+
+       if (!init) return;
 
        CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
 
@@ -499,6 +515,8 @@ static void build_SYS_str_reasons()
        /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
         * as required by ERR_load_strings. */
 
+       init = 0;
+       
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
        }
 #endif
@@ -528,31 +546,18 @@ static void ERR_STATE_free(ERR_STATE *s)
 
 void ERR_load_ERR_strings(void)
        {
-       static int init=1;
-
-       if (init)
-               {
-               init=0;
-               /* We put the first-time check code here to reduce the number of
-                * times it is called (then it doesn't get called from
-                * ERR_load_strings() loads of times). */
-               err_fns_check();
+       err_fns_check();
 #ifndef OPENSSL_NO_ERR
-               ERR_load_strings(0,ERR_str_libraries);
-               ERR_load_strings(0,ERR_str_reasons);
-               ERR_load_strings(ERR_LIB_SYS,ERR_str_functs);
-               build_SYS_str_reasons();
-               ERR_load_strings(ERR_LIB_SYS,SYS_str_reasons);
+       err_load_strings(0,ERR_str_libraries);
+       err_load_strings(0,ERR_str_reasons);
+       err_load_strings(ERR_LIB_SYS,ERR_str_functs);
+       build_SYS_str_reasons();
+       err_load_strings(ERR_LIB_SYS,SYS_str_reasons);
 #endif
-               }
        }
 
-void ERR_load_strings(int lib, ERR_STRING_DATA *str)
+static void err_load_strings(int lib, ERR_STRING_DATA *str)
        {
-       /* Do this if it hasn't been done already (NB: The order of the "init=0"
-        * statement and the recursive calls back to this function prevent a
-        * loop). */
-       ERR_load_ERR_strings();
        while (str->error)
                {
                str->error|=ERR_PACK(lib,0,0);
@@ -561,6 +566,12 @@ void ERR_load_strings(int lib, ERR_STRING_DATA *str)
                }
        }
 
+void ERR_load_strings(int lib, ERR_STRING_DATA *str)
+       {
+       ERR_load_ERR_strings();
+       err_load_strings(lib, str);
+       }
+
 void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
        {
        while(str->error)
@@ -971,4 +982,3 @@ void ERR_add_error_data(int num, ...)
 
        va_end(args);
        }
-