blob: 15ccba3464a83c3c97090dfff507b077aad3fd14 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "port/time.h"
#if !defined HAVE_LOCALTIME_R
/* TODO: port mutexes */
#include <pthread.h> /* for pthread_X */
#include "port/stdbool.h" /* for bool */
#include "port/string.h" /* for memcpy */
struct tm *localtime_r( const time_t *timep, struct tm *result ) {
static pthread_mutex_t mutex;
static bool first = true;
struct tm *local_result;
if( first ) {
pthread_mutex_init( &mutex, NULL );
first = false;
}
pthread_mutex_lock( &mutex );
local_result = localtime( timep );
if( local_result != NULL ) {
memcpy( result, local_result, sizeof( struct tm ) );
}
pthread_mutex_unlock( &mutex );
return ( local_result != NULL ) ? result : NULL;
}
#endif /* !defined HAVE_LOCALTIME_R */
|