systime.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <util/system/platform.h>
  3. #include <util/generic/string.h>
  4. #include <ctime>
  5. // timegm and gmtime_r versions that don't need access to filesystem or a big stack
  6. time_t TimeGM(const struct tm* t);
  7. struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf);
  8. // safe version of ctime, convinient version of ctime_r
  9. TString CTimeR(const time_t* timer);
  10. #ifdef _win_
  11. #include <util/system/winint.h>
  12. #include <winsock2.h>
  13. void FileTimeToTimeval(const FILETIME* ft, struct timeval* tv);
  14. // obtains the current time, expressed as seconds and microseconds since 00:00 UTC, January 1, 1970
  15. int gettimeofday(struct timeval* tp, void*);
  16. // thou should not mix these with non-_r functions
  17. tm* localtime_r(const time_t* clock, tm* result);
  18. tm* gmtime_r(const time_t* clock, tm* result);
  19. char* ctime_r(const time_t* clock, char* buf);
  20. inline time_t timegm(struct tm* t) {
  21. return TimeGM(t);
  22. }
  23. char* strptime(const char* buf, const char* fmt, struct tm* tm); // strptime.cpp
  24. #else
  25. #include <sys/time.h>
  26. #endif
  27. #ifndef timersub
  28. #define timersub(tvp, uvp, vvp) \
  29. do { \
  30. (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
  31. (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
  32. if ((vvp)->tv_usec < 0) { \
  33. (vvp)->tv_sec--; \
  34. (vvp)->tv_usec += 1000000; \
  35. } \
  36. } while (0)
  37. #endif