diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-08-05 17:34:27 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-08-05 17:34:27 (GMT) |
commit | 6fc4ade2bb44a176555703ebc2dbfb54b57e1148 (patch) | |
tree | c52aa91d4f9e35bb2850ea2aea673e56eabc4ee6 /Modules/timemodule.c | |
parent | 1c5471f319a4e5c7bbb56c7ae349b5fe455dc857 (diff) | |
download | cpython-6fc4ade2bb44a176555703ebc2dbfb54b57e1148.zip cpython-6fc4ade2bb44a176555703ebc2dbfb54b57e1148.tar.gz cpython-6fc4ade2bb44a176555703ebc2dbfb54b57e1148.tar.bz2 |
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
exposed in Python.h. This function is similar to POSIX
gettimeofday(struct timeval *tp), but available on platforms without
gettimeofday().
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 59 |
1 files changed, 4 insertions, 55 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c4b5014..879e686 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -3,22 +3,10 @@ #include "Python.h" #include "structseq.h" -#include "timefuncs.h" +#include "_time.h" #define TZNAME_ENCODING "utf-8" -#ifdef __APPLE__ -#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME) - /* - * floattime falls back to ftime when getttimeofday fails because the latter - * might fail on some platforms. This fallback is unwanted on MacOSX because - * that makes it impossible to use a binary build on OSX 10.4 on earlier - * releases of the OS. Therefore claim we don't support ftime. - */ -# undef HAVE_FTIME -#endif -#endif - #include <ctype.h> #ifdef HAVE_SYS_TYPES_H @@ -29,13 +17,6 @@ #include <io.h> #endif -#ifdef HAVE_FTIME -#include <sys/timeb.h> -#if !defined(MS_WINDOWS) && !defined(PYOS_OS2) -extern int ftime(struct timeb *); -#endif /* MS_WINDOWS */ -#endif /* HAVE_FTIME */ - #if defined(__WATCOMC__) && !defined(__QNX__) #include <i86.h> #else @@ -946,44 +927,12 @@ PyInit_time(void) return m; } - -/* Implement floattime() for various platforms */ - static double floattime(void) { - /* There are three ways to get the time: - (1) gettimeofday() -- resolution in microseconds - (2) ftime() -- resolution in milliseconds - (3) time() -- resolution in seconds - In all cases the return value is a float in seconds. - Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may - fail, so we fall back on ftime() or time(). - Note: clock resolution does not imply clock accuracy! */ -#ifdef HAVE_GETTIMEOFDAY - { - struct timeval t; -#ifdef GETTIMEOFDAY_NO_TZ - if (gettimeofday(&t) == 0) - return (double)t.tv_sec + t.tv_usec*0.000001; -#else /* !GETTIMEOFDAY_NO_TZ */ - if (gettimeofday(&t, (struct timezone *)NULL) == 0) - return (double)t.tv_sec + t.tv_usec*0.000001; -#endif /* !GETTIMEOFDAY_NO_TZ */ - } - -#endif /* !HAVE_GETTIMEOFDAY */ - { -#if defined(HAVE_FTIME) - struct timeb t; - ftime(&t); - return (double)t.time + (double)t.millitm * (double)0.001; -#else /* !HAVE_FTIME */ - time_t secs; - time(&secs); - return (double)secs; -#endif /* !HAVE_FTIME */ - } + _PyTime_timeval t; + _PyTime_gettimeofday(&t); + return (double)t.tv_sec + t.tv_usec*0.000001; } |