clock_settime.c 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. _syscall2_64(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp)
  13. #elif defined(__NR_clock_settime)
  14. _syscall2(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp)
  15. #else
  16. # include <sys/time.h>
  17. int clock_settime(clockid_t clock_id, const struct timespec* tp)
  18. {
  19. struct timeval tv;
  20. int retval = -1;
  21. if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) {
  22. errno = EINVAL;
  23. return -1;
  24. }
  25. switch (clock_id) {
  26. case CLOCK_REALTIME:
  27. TIMESPEC_TO_TIMEVAL(&tv, tp);
  28. retval = settimeofday(&tv, NULL);
  29. break;
  30. default:
  31. errno = EINVAL;
  32. break;
  33. }
  34. return retval;
  35. }
  36. #endif