clock_settime.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * clock_settime() for uClibc
  3. *
  4. * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <time.h>
  11. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_settime64)
  12. #include "internal/time64_helpers.h"
  13. int clock_settime(clockid_t clock_id, const struct timespec *tp)
  14. {
  15. return INLINE_SYSCALL(clock_settime64, 2, clock_id, TO_TS64_P(tp));
  16. }
  17. #elif defined(__NR_clock_settime)
  18. _syscall2(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp)
  19. #else
  20. # include <sys/time.h>
  21. int clock_settime(clockid_t clock_id, const struct timespec* tp)
  22. {
  23. struct timeval tv;
  24. int retval = -1;
  25. if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) {
  26. errno = EINVAL;
  27. return -1;
  28. }
  29. switch (clock_id) {
  30. case CLOCK_REALTIME:
  31. TIMESPEC_TO_TIMEVAL(&tv, tp);
  32. retval = settimeofday(&tv, NULL);
  33. break;
  34. default:
  35. errno = EINVAL;
  36. break;
  37. }
  38. return retval;
  39. }
  40. #endif