1 /* 2 * sys-time.h - time.h wrapper for localtime_r() and gmtime_r() 3 * 4 * Copyright(c) 2015 Glenn Strauss gstrauss()gluelogic.com All rights reserved 5 * License: BSD 3-clause (same as lighttpd) 6 */ 7 #ifndef INCLUDED_SYS_TIME_H 8 #define INCLUDED_SYS_TIME_H 9 #include "first.h" 10 11 #ifdef HAVE_SYS_TIME_H 12 #include <sys/time.h>/* gettimeofday() */ 13 #endif 14 #include <time.h> /* time() localtime_r() gmtime_r() strftime() */ 15 16 /*(provide rudimentary localtime_r() and gmtime_r() for platforms lacking) 17 *(Note that 'result' preprocessor arg is repeated, so callers should avoid 18 * side-effects. Also note that there is still a race condition before the 19 * result of localtime()/gmtime() is copied. In any case, this exists here 20 * so that the rest of the code can use localtime_r() and gmtime_r() syntax. 21 * Platforms requiring thread-safety and lacking localtime_r() or gmtime_r() 22 * could turn these into subroutines which take a local mutex to protect the 23 * calls to localtime() or gmtime()) */ 24 #ifndef HAVE_LOCALTIME_R 25 #define localtime_r(timep,result) ((*(result) = *(localtime(timep))), (result)) 26 #endif 27 #ifndef HAVE_GMTIME_R 28 #define gmtime_r(timep,result) ((*(result) = *(gmtime(timep))), (result)) 29 #endif 30 31 #endif 32