Make some global variables static
[openssl.git] / crypto / init.c
index 1bfde6973ceb41c114296ea50f2188f03fc336dd..26021d9494f20b95fdf26352d18a454dfc4d025a 100644 (file)
  *
  */
 
  *
  */
 
-#include <openssl/e_os2.h>
-
-#if defined(OPENSSL_SYS_WINDOWS) && !defined(_WIN32_WINNT)
-/*
- * We default to requiring Windows Vista, Windows Server 2008 or later. We can
- * support lower versions if _WIN32_WINNT is explicity defined to something
- * less
- */
-# define _WIN32_WINNT 0x0600
-#endif
-
 #include <internal/cryptlib_int.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
 #include <internal/cryptlib_int.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
@@ -106,11 +95,19 @@ static void ossl_init_thread_stop_cleanup(void)
 }
 
 static struct thread_local_inits_st *local = NULL;
 }
 
 static struct thread_local_inits_st *local = NULL;
-void *ossl_init_get_thread_local(int alloc)
+static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
 {
 {
+    static struct thread_local_inits_st *tmp;
+
+    tmp = local;
+
     if (local == NULL && alloc)
     if (local == NULL && alloc)
-        local = OPENSSL_zalloc(sizeof(*local));
-    return local;
+        tmp = local = OPENSSL_zalloc(sizeof(*local));
+
+    if (!alloc)
+        local = NULL;
+
+    return tmp;
 }
 
 #elif defined(OPENSSL_SYS_WINDOWS)
 }
 
 #elif defined(OPENSSL_SYS_WINDOWS)
@@ -171,7 +168,7 @@ static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
 }
 # endif
 
 }
 # endif
 
-DWORD threadstopkey = TLS_OUT_OF_INDEXES;
+static DWORD threadstopkey = TLS_OUT_OF_INDEXES;
 
 static int ossl_init_setup_thread_stop(void)
 {
 
 static int ossl_init_setup_thread_stop(void)
 {
@@ -193,7 +190,7 @@ static void ossl_init_thread_stop_cleanup(void)
     }
 }
 
     }
 }
 
-void *ossl_init_get_thread_local(int alloc)
+static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
 {
     struct thread_local_inits_st *local = TlsGetValue(threadstopkey);
 
 {
     struct thread_local_inits_st *local = TlsGetValue(threadstopkey);
 
@@ -201,6 +198,9 @@ void *ossl_init_get_thread_local(int alloc)
         local = OPENSSL_zalloc(sizeof *local);
         TlsSetValue(threadstopkey, local);
     }
         local = OPENSSL_zalloc(sizeof *local);
         TlsSetValue(threadstopkey, local);
     }
+    if (!alloc) {
+        TlsSetValue(threadstopkey, NULL);
+    }
 
     return local;
 }
 
     return local;
 }
@@ -208,7 +208,7 @@ void *ossl_init_get_thread_local(int alloc)
 #else /* pthreads */
 # include <pthread.h>
 
 #else /* pthreads */
 # include <pthread.h>
 
-pthread_key_t threadstopkey;
+static pthread_key_t threadstopkey;
 
 typedef pthread_once_t OPENSSL_INIT_ONCE;
 # define OPENSSL_INIT_ONCE_STATIC_INIT          PTHREAD_ONCE_INIT
 
 typedef pthread_once_t OPENSSL_INIT_ONCE;
 # define OPENSSL_INIT_ONCE_STATIC_INIT          PTHREAD_ONCE_INIT
@@ -238,7 +238,7 @@ static void ossl_init_thread_stop_cleanup(void)
 {
 }
 
 {
 }
 
-void *ossl_init_get_thread_local(int alloc)
+static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
 {
     struct thread_local_inits_st *local = pthread_getspecific(threadstopkey);
 
 {
     struct thread_local_inits_st *local = pthread_getspecific(threadstopkey);
 
@@ -246,6 +246,9 @@ void *ossl_init_get_thread_local(int alloc)
         local = OPENSSL_zalloc(sizeof *local);
         pthread_setspecific(threadstopkey, local);
     }
         local = OPENSSL_zalloc(sizeof *local);
         pthread_setspecific(threadstopkey, local);
     }
+    if (!alloc) {
+        pthread_setspecific(threadstopkey, NULL);
+    }
 
     return local;
 }
 
     return local;
 }