clock_settime.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * clock_settime() for uClibc
  3. *
  4. * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU Library General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #define settimeofday __settimeofday
  22. #define _GNU_SOURCE
  23. #include "syscalls.h"
  24. #include <time.h>
  25. #include <sys/time.h>
  26. #ifdef __NR_clock_settime
  27. _syscall2(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp);
  28. #else
  29. int clock_settime(clockid_t clock_id, const struct timespec* tp)
  30. {
  31. struct timeval tv;
  32. int retval = -1;
  33. if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) {
  34. errno = EINVAL;
  35. return -1;
  36. }
  37. switch (clock_id) {
  38. case CLOCK_REALTIME:
  39. TIMESPEC_TO_TIMEVAL(&tv, tp);
  40. retval = settimeofday(&tv, NULL);
  41. break;
  42. default:
  43. errno = EINVAL;
  44. break;
  45. }
  46. return retval;
  47. }
  48. #endif