settimeofday.c 930 B

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