Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
888 B

  1. /*
  2. * Public domain
  3. * sys/time.h compatibility shim
  4. */
  5. #ifndef LIBCOMPAT_SYS_TIME_H
  6. #define LIBCOMPAT_SYS_TIME_H
  7. #include_next <sys/time.h>
  8. #include <stdint.h>
  9. int adjfreq(const int64_t *freq, int64_t *oldfreq);
  10. #ifdef __sun
  11. static inline int sun_adjtime(struct timeval *delta, struct timeval *olddelta)
  12. {
  13. struct timeval zero = {0};
  14. int rc;
  15. /*
  16. * adjtime on Solaris appears to handle a NULL delta differently than
  17. * other OSes. Fill in a dummy value as necessary.
  18. */
  19. if (delta)
  20. rc = adjtime(delta, olddelta);
  21. else
  22. rc = adjtime(&zero, olddelta);
  23. /*
  24. * Old delta on Solaris frequently gets stuck with 1 ms left.
  25. * Round down to 0 in this case so we do not get flapping clock sync.
  26. */
  27. if (rc == 0 && olddelta &&
  28. olddelta->tv_sec == 0 && olddelta->tv_usec == 1)
  29. olddelta->tv_usec = 0;
  30. return rc;
  31. }
  32. #define adjtime(d, o) sun_adjtime(d, o)
  33. #endif
  34. #endif