gettimeofday.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* source: cygwin-1.5.24-2-src/cygwin-1.5.24-2/winsup/mingw/mingwex/gettimeofday.c */
  2. /*
  3. * gettimeofday
  4. * Implementation according to:
  5. * The Open Group Base Specifications Issue 6
  6. * IEEE Std 1003.1, 2004 Edition
  7. */
  8. /*
  9. * THIS SOFTWARE IS NOT COPYRIGHTED
  10. *
  11. * This source code is offered for use in the public domain. You may
  12. * use, modify or distribute it freely.
  13. *
  14. * This code is distributed in the hope that it will be useful but
  15. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  16. * DISCLAIMED. This includes but is not limited to warranties of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. *
  19. * Contributed by:
  20. * Danny Smith <dannysmith@users.sourceforge.net>
  21. */
  22. #include <sys/time.h>
  23. #ifdef __MINGW32__
  24. #define WIN32_LEAN_AND_MEAN
  25. #include <windows.h>
  26. /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
  27. #define _W32_FT_OFFSET (116444736000000000ULL)
  28. int __cdecl gettimeofday(struct timeval *__restrict__ tp,
  29. void *__restrict__ tzp __attribute__((unused)))
  30. {
  31. union {
  32. unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
  33. FILETIME ft;
  34. } _now;
  35. if(tp)
  36. {
  37. GetSystemTimeAsFileTime (&_now.ft);
  38. tp->tv_usec=(long)((_now.ns100 / 10ULL) % 1000000ULL );
  39. tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000ULL);
  40. }
  41. /* Always return 0 as per Open Group Base Specifications Issue 6.
  42. Do not set errno on error. */
  43. return 0;
  44. }
  45. #endif // __MINGW32__