time.h 954 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2. /*
  3. * time definitions for NOLIBC
  4. * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
  5. */
  6. /* make sure to include all global symbols */
  7. #include "../nolibc.h"
  8. #ifndef _NOLIBC_SYS_TIME_H
  9. #define _NOLIBC_SYS_TIME_H
  10. #include "../arch.h"
  11. #include "../sys.h"
  12. static int sys_clock_gettime(clockid_t clockid, struct timespec *tp);
  13. /*
  14. * int gettimeofday(struct timeval *tv, struct timezone *tz);
  15. */
  16. static __attribute__((unused))
  17. int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
  18. {
  19. (void) tz; /* Non-NULL tz is undefined behaviour */
  20. struct timespec tp;
  21. int ret;
  22. ret = sys_clock_gettime(CLOCK_REALTIME, &tp);
  23. if (!ret && tv) {
  24. tv->tv_sec = tp.tv_sec;
  25. tv->tv_usec = (uint32_t)tp.tv_nsec / 1000;
  26. }
  27. return ret;
  28. }
  29. static __attribute__((unused))
  30. int gettimeofday(struct timeval *tv, struct timezone *tz)
  31. {
  32. return __sysret(sys_gettimeofday(tv, tz));
  33. }
  34. #endif /* _NOLIBC_SYS_TIME_H */