1 #ifndef __UTIL_TIMEFMT_H
2 #define __UTIL_TIMEFMT_H
6 #define INVALID_TIME_TEXT "(invalid)"
10 /* safe localtime formatting - strftime()-using version */
11 #define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
14 whentm = localtime(&when); \
17 strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
18 buffer[bufsize-1] = 0; \
22 strftime(buffer, bufsize, fmt, whentm); \
28 /* fallback when strftime/localtime not available */
29 #define FMT_LOCALTIME(buffer,bufsize,fmt,when) \
31 ctime_r(when,buffer); \
36 #define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
38 time_t __current_time; \
39 time(&__current_time); \
40 FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
43 #endif /* !__UTIL_H */