settimeofday.c 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * settimeofday() for uClibc
  4. *
  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. #ifdef __USE_BSD
  11. # include <sys/time.h>
  12. # ifdef __NR_settimeofday
  13. _syscall2(int, settimeofday, const struct timeval *, tv,
  14. const struct timezone *, tz)
  15. # elif defined __USE_SVID && defined __NR_stime
  16. # define __need_NULL
  17. # include <stddef.h>
  18. # include <errno.h>
  19. # include <time.h>
  20. int settimeofday(const struct timeval *tv, const struct timezone *tz)
  21. {
  22. time_t when;
  23. if (tv == NULL) {
  24. __set_errno(EINVAL);
  25. return -1;
  26. }
  27. if (tz != NULL || tv->tv_usec % 1000000 != 0) {
  28. __set_errno(ENOSYS);
  29. return -1;
  30. }
  31. when = tv->tv_sec + (tv->tv_usec / 1000000);
  32. return stime(&when);
  33. }
  34. # endif
  35. # if defined __NR_settimeofday || (defined __USE_SVID && defined __NR_stime)
  36. libc_hidden_def(settimeofday)
  37. # endif
  38. #endif