Ticket #1711: i18n: context and cleanup in file prompt strings
[midnight-commander.git] / src / timefmt.h
blobb93a135852b7b77786e9c763b40f2c56e7df10ee
2 /** \file timefmt.h
3 * \brief Header: time formating macroses
4 */
6 #ifndef __UTIL_TIMEFMT_H
7 #define __UTIL_TIMEFMT_H
9 #include <sys/types.h>
11 #define INVALID_TIME_TEXT "(invalid)"
13 #ifdef HAVE_STRFTIME
15 /* safe localtime formatting - strftime()-using version */
16 #define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
17 { \
18 struct tm *whentm; \
19 whentm = localtime(&when); \
20 if (whentm == NULL) \
21 { \
22 strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
23 buffer[bufsize-1] = 0; \
24 } \
25 else \
26 { \
27 strftime(buffer, bufsize, fmt, whentm); \
28 } \
29 } \
31 #else
33 /* fallback when strftime/localtime not available */
34 #define FMT_LOCALTIME(buffer,bufsize,fmt,when) \
35 { \
36 ctime_r(when,buffer); \
37 } \
39 #endif
41 #define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
42 { \
43 time_t __current_time; \
44 time(&__current_time); \
45 FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
48 #endif /* !__UTIL_H */