clock_settime.c 857 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #define _GNU_SOURCE
  10. #include "syscalls.h"
  11. #include <time.h>
  12. #include <sys/time.h>
  13. #ifdef __NR_clock_settime
  14. _syscall2(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp);
  15. #else
  16. libc_hidden_proto(settimeofday)
  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