aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdtime
diff options
context:
space:
mode:
authorEdwin Groothuis <edwin@FreeBSD.org>2009-09-14 11:20:45 +0000
committerEdwin Groothuis <edwin@FreeBSD.org>2009-09-14 11:20:45 +0000
commit8a1df0ef4e29e1a0bc33bea95cef8a20377931ef (patch)
treebfd4113307d4250ba3aea5722a59b4bfe9a276c2 /lib/libc/stdtime
parentb53c4efaa1b760d27c4db4c4dfd149c349fb2f31 (diff)
downloadsrc-8a1df0ef4e29e1a0bc33bea95cef8a20377931ef.tar.gz
src-8a1df0ef4e29e1a0bc33bea95cef8a20377931ef.zip
Improve the way failure of pthread_key_create() gets detected.
PR: threads/138603 Submitted by: Mikulas Patocka MFC after: 1 week
Notes
Notes: svn path=/head/; revision=197189
Diffstat (limited to 'lib/libc/stdtime')
-rw-r--r--lib/libc/stdtime/localtime.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c
index e0ed73f7d96f..9fc5f3ee99b7 100644
--- a/lib/libc/stdtime/localtime.c
+++ b/lib/libc/stdtime/localtime.c
@@ -21,6 +21,7 @@ __FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
+#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include "private.h"
@@ -1413,13 +1414,16 @@ const time_t * const timep;
static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t localtime_key = -1;
struct tm *p_tm;
+ int r;
if (__isthreaded != 0) {
if (localtime_key < 0) {
_pthread_mutex_lock(&localtime_mutex);
if (localtime_key < 0) {
- if (_pthread_key_create(&localtime_key, free) < 0) {
+ if ((r = _pthread_key_create(&localtime_key,
+ free)) != 0) {
_pthread_mutex_unlock(&localtime_mutex);
+ errno = r;
return(NULL);
}
}
@@ -1512,13 +1516,16 @@ const time_t * const timep;
static pthread_mutex_t gmtime_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t gmtime_key = -1;
struct tm *p_tm;
+ int r;
if (__isthreaded != 0) {
if (gmtime_key < 0) {
_pthread_mutex_lock(&gmtime_mutex);
if (gmtime_key < 0) {
- if (_pthread_key_create(&gmtime_key, free) < 0) {
+ if ((r = _pthread_key_create(&gmtime_key,
+ free)) != 0) {
_pthread_mutex_unlock(&gmtime_mutex);
+ errno = r;
return(NULL);
}
}