summaryrefslogtreecommitdiff
path: root/lib/version.c
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2016-03-16 19:13:42 -0400
committerJay Satiro <raysatiro@yahoo.com>2016-03-16 19:13:42 -0400
commit80015cdd52145bd95b98e0e456540c6da3120f98 (patch)
treed4cd9195c28a352c27943dcc16f422d44d5d0baf /lib/version.c
parent0e18b8b1071d1101e41bd78d69db64d1514383fc (diff)
downloadcurl-80015cdd52145bd95b98e0e456540c6da3120f98.tar.gz
version: thread safety
Diffstat (limited to 'lib/version.c')
-rw-r--r--lib/version.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/version.c b/lib/version.c
index 7f14fa5ca..f693feeda 100644
--- a/lib/version.c
+++ b/lib/version.c
@@ -64,13 +64,25 @@
#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
#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)
{
+ static bool initialized;
static char version[200];
char *ptr = version;
size_t len;
size_t left = sizeof(version);
+ if(initialized)
+ return version;
+
strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
len = strlen(ptr);
left -= len;
@@ -160,6 +172,7 @@ char *curl_version(void)
}
#endif
+ initialized = true;
return version;
}
@@ -323,12 +336,18 @@ static curl_version_info_data version_info = {
curl_version_info_data *curl_version_info(CURLversion stamp)
{
+ static bool initialized;
#ifdef USE_LIBSSH2
static char ssh_buffer[80];
#endif
-
#ifdef USE_SSL
static char ssl_buffer[80];
+#endif
+
+ if(initialized)
+ return &version_info;
+
+#ifdef USE_SSL
Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
version_info.ssl_version = ssl_buffer;
#endif
@@ -370,5 +389,6 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
(void)stamp; /* avoid compiler warnings, we don't use this */
+ initialized = true;
return &version_info;
}