Browse Source
sys-time.h - localtime_r,gmtime_r macros if needed provide rudimentary localtime_r() and gmtime_r() if not present (wraps localtime() and gmtime() funtions, but are not thread-safe since they do not take a lock around access to localtime() and gmtime()) (import from one of my development branches from 2015)master
2 changed files with 34 additions and 1 deletions
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* sys-time.h - time.h wrapper for localtime_r() and gmtime_r() |
||||
* |
||||
* Copyright(c) 2015 Glenn Strauss gstrauss()gluelogic.com All rights reserved |
||||
* License: BSD 3-clause (same as lighttpd) |
||||
*/ |
||||
#ifndef INCLUDED_SYS_TIME_H |
||||
#define INCLUDED_SYS_TIME_H |
||||
/* _XOPEN_SOURCE for strptime() */ |
||||
#ifndef _XOPEN_SOURCE |
||||
#define _XOPEN_SOURCE 700 |
||||
#endif |
||||
#include "first.h" |
||||
|
||||
#include <sys/time.h>/* gettimeofday() */ |
||||
#include <time.h> /* time() localtime_r() gmtime_r() strftime() strptime() */ |
||||
|
||||
/*(provide rudimentary localtime_r() and gmtime_r() for platforms lacking)
|
||||
*(Note that 'result' preprocessor arg is repeated, so callers should avoid |
||||
* side-effects. Also note that there is still a race condition before the |
||||
* result of localtime()/gmtime() is copied. In any case, this exists here |
||||
* so that the rest of the code can use localtime_r() and gmtime_r() syntax. |
||||
* Platforms requiring thread-safety and lacking localtime_r() or gmtime_r() |
||||
* could turn these into subroutines which take a local mutex to protect the |
||||
* calls to localtime() or gmtime()) */ |
||||
#ifndef HAVE_LOCALTIME_R |
||||
#define localtime_r(timep,result) ((*(result) = *(localtime(timep))), (result)) |
||||
#endif |
||||
#ifndef HAVE_GMTIME_R |
||||
#define gmtime_r(timep,result) ((*(result) = *(gmtime(timep))), (result)) |
||||
#endif |
||||
|
||||
#endif |
Loading…
Reference in new issue