settimeofday.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. int settimeofday(const struct timeval *tv, const struct timezone *tz)
  13. {
  14. if (!tv)
  15. return 0;
  16. struct timespec __ts = {
  17. .tv_sec = tv->tv_sec,
  18. .tv_nsec = tv->tv_usec * 1000
  19. };
  20. return clock_settime(CLOCK_REALTIME, &__ts);
  21. }
  22. # elif defined __USE_SVID && defined __NR_stime
  23. # define __need_NULL
  24. # include <stddef.h>
  25. # include <errno.h>
  26. # include <time.h>
  27. int settimeofday(const struct timeval *tv, const struct timezone *tz)
  28. {
  29. time_t when;
  30. if (tv == NULL) {
  31. __set_errno(EINVAL);
  32. return -1;
  33. }
  34. if (tz != NULL || tv->tv_usec % 1000000 != 0) {
  35. __set_errno(ENOSYS);
  36. return -1;
  37. }
  38. when = tv->tv_sec + (tv->tv_usec / 1000000);
  39. return stime(&when);
  40. }
  41. # endif
  42. # if defined __NR_settimeofday || defined(__UCLIBC_USE_TIME64__) || (defined __USE_SVID && defined __NR_stime)
  43. libc_hidden_def(settimeofday)
  44. # endif