Merge branch '1926_ncurses_ctrl_backslash'
[midnight-commander.git] / lib / timefmt.h
blobe80791b6e5b0202b9667508ae1a5019a0dfda11a
2 /** \file timefmt.h
3 * \brief Header: time formating macroses
4 */
6 #ifndef __UTIL_TIMEFMT_H
7 #define __UTIL_TIMEFMT_H
9 #include <sys/time.h>
10 #include <sys/types.h>
12 #define INVALID_TIME_TEXT "(invalid)"
14 /* safe localtime formatting - strftime()-using version */
15 #define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
16 { \
17 struct tm *whentm; \
18 whentm = localtime(&when); \
19 if (whentm == NULL) \
20 { \
21 strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
22 buffer[bufsize-1] = 0; \
23 } \
24 else \
25 { \
26 strftime(buffer, bufsize, fmt, whentm); \
27 } \
28 } \
30 #define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
31 { \
32 time_t __current_time; \
33 time(&__current_time); \
34 FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
37 #endif /* !__UTIL_H */