mc/lib/timefmt.h
Slava Zanko feb733663f Code indentation in lib directory
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2010-11-24 10:27:20 +03:00

51 lines
2.1 KiB
C

/** \file timefmt.h
* \brief Header: time formating macroses
*/
#ifndef MC__UTIL_TIMEFMT_H
#define MC__UTIL_TIMEFMT_H
#include <sys/time.h>
#include <sys/types.h>
/*** typedefs(not structures) and defined constants **********************************************/
#define INVALID_TIME_TEXT "(invalid)"
/* safe localtime formatting - strftime()-using version */
#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
{ \
struct tm *whentm; \
whentm = localtime(&when); \
if (whentm == NULL) \
{ \
strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
buffer[bufsize-1] = 0; \
} \
else \
{ \
strftime(buffer, bufsize, fmt, whentm); \
} \
} \
#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
{ \
time_t __current_time; \
time(&__current_time); \
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
}
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
/*** inline functions ****************************************************************************/
#endif /* !__UTIL_H */