Browse Source

[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)
master
Glenn Strauss 7 months ago
parent
commit
f928f6d827
  1. 2
      src/Makefile.am
  2. 33
      src/sys-time.h

2
src/Makefile.am

@ -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 \

33
src/sys-time.h

@ -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…
Cancel
Save