systime.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 the file system or a large stack
  6. time_t TimeGM(const struct tm* t);
  7. // the same as gmtime_r, but 3–5 times faster
  8. struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf);
  9. // safe version of ctime, convenient version of ctime_r
  10. TString CTimeR(const time_t* timer);
  11. #ifdef _win_
  12. #include <util/system/winint.h>
  13. #include <winsock2.h>
  14. // Convert FILETIME to timeval: seconds and microseconds.
  15. void FileTimeToTimeval(const FILETIME* ft, struct timeval* tv);
  16. // Convert FILETIME to timespec: seconds and nanoseconds.
  17. void FileTimeToTimespec(const FILETIME& ft, struct timespec* ts);
  18. // Obtain the current time, expressed as seconds and microseconds since 00:00 UTC, January 1, 1970
  19. int gettimeofday(struct timeval* tp, void*);
  20. // You should not mix these with non-_r functions
  21. tm* localtime_r(const time_t* clock, tm* result);
  22. tm* gmtime_r(const time_t* clock, tm* result);
  23. char* ctime_r(const time_t* clock, char* buf);
  24. inline time_t timegm(struct tm* t) {
  25. return TimeGM(t);
  26. }
  27. char* strptime(const char* buf, const char* fmt, struct tm* tm); // strptime.cpp
  28. #else
  29. #include <sys/time.h>
  30. #endif
  31. #ifndef timersub
  32. #define timersub(tvp, uvp, vvp) \
  33. do { \
  34. (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
  35. (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
  36. if ((vvp)->tv_usec < 0) { \
  37. (vvp)->tv_sec--; \
  38. (vvp)->tv_usec += 1000000; \
  39. } \
  40. } while (0)
  41. #endif