diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-02-28 11:46:52 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-02-28 11:46:52 +0100 |
commit | b4cf78d1eaed900aa6acbcab01bc8693c88b0275 (patch) | |
tree | a4682a8004ee45b46f4f6d4c5e5b980ec1692ea1 /src/port/time.c | |
parent | 2e27ca524f38f537e6bf706c7aa7dce79a745e17 (diff) | |
download | wolfbones-b4cf78d1eaed900aa6acbcab01bc8693c88b0275.tar.gz wolfbones-b4cf78d1eaed900aa6acbcab01bc8693c88b0275.tar.bz2 |
added localtime_r and a stub (which needs mutexes, which we still have to port!)
Diffstat (limited to 'src/port/time.c')
-rw-r--r-- | src/port/time.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/port/time.c b/src/port/time.c new file mode 100644 index 0000000..15ccba3 --- /dev/null +++ b/src/port/time.c @@ -0,0 +1,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 */ |