[core] sys-time.h - localtime_r,gmtime_r macros

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)
Glenn Strauss 2020-11-21 09:35:33 -05:00
parent 29f50bdeb0
commit f928f6d827
2 changed files with 34 additions and 1 deletions

View File

@ -466,7 +466,7 @@ hdr = base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
configparser.h mod_ssi_exprparser.h \
rand.h \
sys-crypto.h sys-crypto-md.h \
sys-endian.h sys-mmap.h sys-socket.h sys-strings.h \
sys-endian.h sys-mmap.h sys-socket.h sys-strings.h sys-time.h \
mod_cml.h mod_cml_funcs.h \
safe_memclear.h sock_addr.h status_counter.h \
mod_magnet_cache.h \

src/sys-time.h Normal file
View File

@ -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)
/* _XOPEN_SOURCE for strptime() */
#define _XOPEN_SOURCE 700
#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()) */
#define localtime_r(timep,result) ((*(result) = *(localtime(timep))), (result))
#define gmtime_r(timep,result) ((*(result) = *(gmtime(timep))), (result))