gettimeofday.c 724 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * gettimeofday() 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. #include <sys/time.h>
  10. #include <time.h>
  11. #ifdef __VDSO_SUPPORT__
  12. #include "ldso.h"
  13. #endif
  14. int gettimeofday(struct timeval * tv, __timezone_ptr_t tz) {
  15. if (!tv)
  16. return 0;
  17. #if defined(__VDSO_SUPPORT__) && defined(ARCH_VDSO_GETTIMEOFDAY)
  18. return ARCH_VDSO_GETTIMEOFDAY(tv, tz);
  19. #else
  20. struct timespec __ts;
  21. int __ret = clock_gettime(CLOCK_REALTIME, &__ts);
  22. tv->tv_sec = __ts.tv_sec;
  23. tv->tv_usec = (suseconds_t)__ts.tv_nsec / 1000;
  24. return __ret;
  25. #endif
  26. }
  27. libc_hidden_def(gettimeofday)