You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. #include "Python.h"
  2. #ifdef __APPLE__
  3. #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
  4. /*
  5. * _PyTime_gettimeofday falls back to ftime when getttimeofday fails because the latter
  6. * might fail on some platforms. This fallback is unwanted on MacOSX because
  7. * that makes it impossible to use a binary build on OSX 10.4 on earlier
  8. * releases of the OS. Therefore claim we don't support ftime.
  9. */
  10. # undef HAVE_FTIME
  11. #endif
  12. #endif
  13. #ifdef HAVE_FTIME
  14. #include <sys/timeb.h>
  15. #if !defined(MS_WINDOWS) && !defined(PYOS_OS2)
  16. extern int ftime(struct timeb *);
  17. #endif /* MS_WINDOWS */
  18. #endif /* HAVE_FTIME */
  19. void
  20. _PyTime_gettimeofday(_PyTime_timeval *tp)
  21. {
  22. /* There are three ways to get the time:
  23. (1) gettimeofday() -- resolution in microseconds
  24. (2) ftime() -- resolution in milliseconds
  25. (3) time() -- resolution in seconds
  26. In all cases the return value in a timeval struct.
  27. Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
  28. fail, so we fall back on ftime() or time().
  29. Note: clock resolution does not imply clock accuracy! */
  30. #ifdef HAVE_GETTIMEOFDAY
  31. #ifdef GETTIMEOFDAY_NO_TZ
  32. if (gettimeofday(tp) == 0)
  33. return;
  34. #else /* !GETTIMEOFDAY_NO_TZ */
  35. if (gettimeofday(tp, (struct timezone *)NULL) == 0)
  36. return;
  37. #endif /* !GETTIMEOFDAY_NO_TZ */
  38. #endif /* !HAVE_GETTIMEOFDAY */
  39. #if defined(HAVE_FTIME)
  40. {
  41. struct timeb t;
  42. ftime(&t);
  43. tp->tv_sec = t.time;
  44. tp->tv_usec = t.millitm * 1000;
  45. }
  46. #else /* !HAVE_FTIME */
  47. tp->tv_sec = time(NULL);
  48. tp->tv_usec = 0;
  49. #endif /* !HAVE_FTIME */
  50. return;
  51. }
  52. void
  53. _PyTime_Init()
  54. {
  55. /* Do nothing. Needed to force linking. */
  56. }