clock_settime.c 808 B

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