gettimeofday.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #ifdef __VDSO_SUPPORT__
  15. typedef int (*gettimeofday_func)(struct timeval * tv, __timezone_ptr_t tz);
  16. #endif
  17. int gettimeofday(struct timeval * tv, __timezone_ptr_t tz) {
  18. #ifdef __VDSO_SUPPORT__
  19. if ( _dl__vdso_gettimeofday != 0 ){
  20. gettimeofday_func func= _dl__vdso_gettimeofday;
  21. return func( tv, tz );
  22. }else{
  23. _syscall2_body(int, gettimeofday, struct timeval *, tv, __timezone_ptr_t, tz)
  24. }
  25. #else
  26. if (!tv)
  27. return 0;
  28. struct timespec __ts;
  29. int __ret = clock_gettime(CLOCK_REALTIME, &__ts);
  30. tv->tv_sec = __ts.tv_sec;
  31. tv->tv_usec = (suseconds_t)__ts.tv_nsec / 1000;
  32. return __ret;
  33. #endif
  34. }
  35. libc_hidden_def(gettimeofday)