clock_settime.c 840 B

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