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