1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

version: thread safety

This commit is contained in:
Jay Satiro 2016-03-16 19:13:42 -04:00
parent 0e18b8b107
commit 80015cdd52
2 changed files with 26 additions and 2 deletions

View File

@ -79,6 +79,8 @@
#include "curl_memory.h" #include "curl_memory.h"
#include "memdebug.h" #include "memdebug.h"
void curl_version_init();
/* win32_cleanup() is for win32 socket cleanup functionality, the opposite /* win32_cleanup() is for win32 socket cleanup functionality, the opposite
of win32_init() */ of win32_init() */
static void win32_cleanup(void) static void win32_cleanup(void)
@ -280,7 +282,9 @@ static CURLcode global_init(long flags, bool memoryfuncs)
if(flags & CURL_GLOBAL_ACK_EINTR) if(flags & CURL_GLOBAL_ACK_EINTR)
Curl_ack_eintr = 1; Curl_ack_eintr = 1;
init_flags = flags; init_flags = flags;
curl_version_init();
return CURLE_OK; return CURLE_OK;
} }

View File

@ -64,13 +64,25 @@
#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
#endif #endif
/* For thread safety purposes this function is called by global_init so that
the static data in both version functions is initialized. */
void curl_version_init()
{
curl_version();
curl_version_info(CURLVERSION_NOW);
}
char *curl_version(void) char *curl_version(void)
{ {
static bool initialized;
static char version[200]; static char version[200];
char *ptr = version; char *ptr = version;
size_t len; size_t len;
size_t left = sizeof(version); size_t left = sizeof(version);
if(initialized)
return version;
strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION); strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
len = strlen(ptr); len = strlen(ptr);
left -= len; left -= len;
@ -160,6 +172,7 @@ char *curl_version(void)
} }
#endif #endif
initialized = true;
return version; return version;
} }
@ -323,12 +336,18 @@ static curl_version_info_data version_info = {
curl_version_info_data *curl_version_info(CURLversion stamp) curl_version_info_data *curl_version_info(CURLversion stamp)
{ {
static bool initialized;
#ifdef USE_LIBSSH2 #ifdef USE_LIBSSH2
static char ssh_buffer[80]; static char ssh_buffer[80];
#endif #endif
#ifdef USE_SSL #ifdef USE_SSL
static char ssl_buffer[80]; static char ssl_buffer[80];
#endif
if(initialized)
return &version_info;
#ifdef USE_SSL
Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer)); Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
version_info.ssl_version = ssl_buffer; version_info.ssl_version = ssl_buffer;
#endif #endif
@ -370,5 +389,6 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
(void)stamp; /* avoid compiler warnings, we don't use this */ (void)stamp; /* avoid compiler warnings, we don't use this */
initialized = true;
return &version_info; return &version_info;
} }