gettimeofday_time32.c 396 B

12345678910111213141516171819
  1. #include "time32.h"
  2. #include <sys/time.h>
  3. #include <errno.h>
  4. #include <stdint.h>
  5. int __gettimeofday_time32(struct timeval32 *tv32, void *tz)
  6. {
  7. struct timeval tv;
  8. if (!tv32) return 0;
  9. int r = gettimeofday(&tv, 0);
  10. if (r) return r;
  11. if (tv.tv_sec < INT32_MIN || tv.tv_sec > INT32_MAX) {
  12. errno = EOVERFLOW;
  13. return -1;
  14. }
  15. tv32->tv_sec = tv.tv_sec;
  16. tv32->tv_usec = tv.tv_usec;
  17. return 0;
  18. }