timefmt.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /** \file timefmt.h
  2. * \brief Header: time formatting functions
  3. */
  4. #ifndef MC__UTIL_TIMEFMT_H
  5. #define MC__UTIL_TIMEFMT_H
  6. #include <sys/time.h>
  7. #include <sys/types.h>
  8. /*** typedefs(not structures) and defined constants **********************************************/
  9. #define MAX_I18NTIMELENGTH 20
  10. #define MIN_I18NTIMELENGTH 10
  11. #define STD_I18NTIMELENGTH 12
  12. #define INVALID_TIME_TEXT "(invalid)"
  13. /* safe localtime formatting - strftime()-using version */
  14. #define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
  15. { \
  16. struct tm *whentm; \
  17. whentm = localtime (&when); \
  18. if (whentm == NULL) \
  19. { \
  20. strncpy (buffer, INVALID_TIME_TEXT, bufsize); \
  21. buffer[bufsize - 1] = 0; \
  22. } \
  23. else \
  24. { \
  25. strftime (buffer, bufsize, fmt, whentm); \
  26. } \
  27. }
  28. #define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
  29. { \
  30. time_t __current_time; \
  31. time (&__current_time); \
  32. FMT_LOCALTIME (buffer, bufsize, fmt, __current_time); \
  33. }
  34. /*** enums ***************************************************************************************/
  35. /*** structures declarations (and typedefs of structures)*****************************************/
  36. /*** global variables defined in .c file *********************************************************/
  37. extern char *user_recent_timeformat; /* time format string for recent dates */
  38. extern char *user_old_timeformat; /* time format string for older dates */
  39. /*** declarations of public functions ************************************************************/
  40. size_t i18n_checktimelength (void);
  41. const char *file_date (time_t when);
  42. /*** inline functions ****************************************************************************/
  43. #endif /* MC__UTIL_TIMEFMT_H */