diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-02-28 15:11:08 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-02-28 15:11:08 +0100 |
commit | 94e643e4b06c66f01e7ddaab9215b5e78413adad (patch) | |
tree | 6238f4920e8032d866adf250fb11497ba92a07b8 /src/port/time.c | |
parent | fc2bfb1089218b8d1e57d331a447af92ab44f8a0 (diff) | |
download | wolfbones-94e643e4b06c66f01e7ddaab9215b5e78413adad.tar.gz wolfbones-94e643e4b06c66f01e7ddaab9215b5e78413adad.tar.bz2 |
localtime_r on native Windows
Diffstat (limited to 'src/port/time.c')
-rw-r--r-- | src/port/time.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/port/time.c b/src/port/time.c index c96d6e2..da97905 100644 --- a/src/port/time.c +++ b/src/port/time.c @@ -46,8 +46,33 @@ struct tm *wolf_port_localtime_r( const time_t *timep, struct tm *result ) { return ( local_result != NULL ) ? result : NULL; } +#else /* defined HAVE_PTHREADS */ + +#if defined _WIN32 + +/* localtime on Windows uses thread-local data to make things thread-safe, + * see MinGW mailing-lists. So we can safely copy the local buffer to the + * result without locking. + * TODO: needs testing of the hypothesis! + */ + +#include "port/string.h" /* for memcpy */ + +struct tm *wolf_port_localtime_r( const time_t *timep, struct tm *result ) { + struct tm *local_result; + + local_result = localtime( timep ); + if( local_result != NULL ) { + memcpy( result, local_result, sizeof( struct tm ) ); + } + + return ( local_result != NULL ) ? result : NULL; +} + #else #error no pthreads, port localtime_r differently! -#endif +#endif /* defined _WIN32 */ + +#endif /* defined HAVE_PTHREADS */ -#endif /* !defined HAVE_LOCALTIME_R */ +#endif /* !defined HAVE_LOCALTIME_R || defined TEST_LOCALTIME_R */ |