settimeofday.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * settimeofday() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #ifdef __USE_BSD
  10. # include <sys/time.h>
  11. # include <time.h>
  12. extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
  13. __THROW;
  14. int settimeofday(const struct timeval *tv, const struct timezone *tz)
  15. {
  16. if (!tv)
  17. return 0;
  18. struct timespec __ts = {
  19. .tv_sec = tv->tv_sec,
  20. .tv_nsec = tv->tv_usec * 1000
  21. };
  22. return clock_settime(CLOCK_REALTIME, &__ts);
  23. }
  24. # elif defined __USE_SVID && defined __NR_stime
  25. # define __need_NULL
  26. # include <stddef.h>
  27. # include <errno.h>
  28. # include <time.h>
  29. int settimeofday(const struct timeval *tv, const struct timezone *tz)
  30. {
  31. time_t when;
  32. if (tv == NULL) {
  33. __set_errno(EINVAL);
  34. return -1;
  35. }
  36. if (tz != NULL || tv->tv_usec % 1000000 != 0) {
  37. __set_errno(ENOSYS);
  38. return -1;
  39. }
  40. when = tv->tv_sec + (tv->tv_usec / 1000000);
  41. return stime(&when);
  42. }
  43. # endif
  44. # if defined __NR_settimeofday || defined(__UCLIBC_USE_TIME64__) || (defined __USE_SVID && defined __NR_stime)
  45. libc_hidden_def(settimeofday)
  46. # endif