Index: configure.in =================================================================== RCS file: /cvsroot/python/python/dist/src/configure.in,v retrieving revision 1.341 diff -u -r1.341 configure.in --- configure.in 15 Aug 2002 13:56:06 -0000 1.341 +++ configure.in 9 Sep 2002 05:45:56 -0000 @@ -2240,6 +2240,23 @@ [Define if nice() returns success/failure instead of the new priority.]) fi +# Look for subsecond timestamps in struct stat +AC_MSG_CHECKING(for tv_nsec in struct stat) +AC_CACHE_VAL(ac_cv_stat_tv_nsec, +AC_TRY_COMPILE([#include ], [ +struct stat st; +st.st_mtim.tv_nsec = 1; +], +ac_cv_stat_tv_nsec = yes, +ac_cv_stat_tv_nsec=no, +ac_cv_stat_tv_nsec=no)) +AC_MSG_RESULT($ac_cv_stat_tv_nsec) +if test "$ac_cv_stat_tv_nsec" = yes +then + AC_DEFINE(HAVE_STAT_TV_NSEC, 1, + [Define if you have struct stat.st_mtim.tv_nsec]) +fi + # On HP/UX 11.0, mvwdelch is a block with a return statement AC_MSG_CHECKING(whether mvwdelch is an expression) AC_CACHE_VAL(ac_cv_mvwdelch_is_expression, Index: pyconfig.h.in =================================================================== RCS file: /cvsroot/python/python/dist/src/pyconfig.h.in,v retrieving revision 1.47 diff -u -r1.47 pyconfig.h.in --- pyconfig.h.in 30 Jul 2002 01:08:28 -0000 1.47 +++ pyconfig.h.in 9 Sep 2002 05:45:56 -0000 @@ -388,6 +388,9 @@ /* Define to 1 if you have the `statvfs' function. */ #undef HAVE_STATVFS +/* Define if you have struct stat.st_mtim.tv_nsec */ +#undef HAVE_STAT_TV_NSEC + /* Define to 1 if you have the header file. */ #undef HAVE_STDARG_H Index: Modules/posixmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v retrieving revision 2.253 diff -u -r2.253 posixmodule.c --- Modules/posixmodule.c 1 Sep 2002 15:06:28 -0000 2.253 +++ Modules/posixmodule.c 9 Sep 2002 05:46:07 -0000 @@ -612,11 +612,28 @@ static PyTypeObject StatResultType; static PyTypeObject StatVFSResultType; +static void +fill_time(PyObject *v, int index, time_t sec, unsigned long nsec) +{ + PyObject *val; + if (nsec) { + val = PyFloat_FromDouble(sec + 1e-9*nsec); + } else { +#if SIZEOF_TIME_T > SIZEOF_LONG + val = PyLong_FromLongLong((LONG_LONG)sec); +#else + val = PyInt_FromLong((long)sec); +#endif + } + PyStructSequence_SET_ITEM(v, index, val); +} + /* pack a system stat C structure into the Python stat tuple (used by posix_stat() and posix_fstat()) */ static PyObject* _pystat_fromstructstat(STRUCT_STAT st) { + unsigned long ansec, mnsec, cnsec; PyObject *v = PyStructSequence_New(&StatResultType); if (v == NULL) return NULL; @@ -643,18 +660,17 @@ #else PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong(st.st_size)); #endif -#if SIZEOF_TIME_T > SIZEOF_LONG - PyStructSequence_SET_ITEM(v, 7, - PyLong_FromLongLong((LONG_LONG)st.st_atime)); - PyStructSequence_SET_ITEM(v, 8, - PyLong_FromLongLong((LONG_LONG)st.st_mtime)); - PyStructSequence_SET_ITEM(v, 9, - PyLong_FromLongLong((LONG_LONG)st.st_ctime)); + +#ifdef HAVE_STAT_TV_NSEC + ansec = st.st_atim.tv_nsec; + mnsec = st.st_mtim.tv_nsec; + cnsec = st.st_ctim.tv_nsec; #else - PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long)st.st_atime)); - PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long)st.st_mtime)); - PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long)st.st_ctime)); + ansec = mnsec = cnsec = 0; #endif + fill_time(v, 7, st.st_atime, ansec); + fill_time(v, 8, st.st_mtime, mnsec); + fill_time(v, 9, st.st_ctime, cnsec); #ifdef HAVE_ST_BLKSIZE PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX, Index: Doc/lib/libos.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libos.tex,v retrieving revision 1.94 diff -u -r1.94 libos.tex --- Doc/lib/libos.tex 7 Aug 2002 15:48:17 -0000 1.94 +++ Doc/lib/libos.tex 9 Sep 2002 05:51:37 -0000 @@ -859,6 +859,9 @@ More items may be added at the end by some implementations. Note that on the Mac OS, the time values are floating point values, like all time values on the Mac OS. +\versionchanged +[On other systems, the values are floats if the system reports + fractions of a second]{2.3} The standard module \refmodule{stat}\refstmodindex{stat} defines functions and constants that are useful for extracting information from a \ctype{stat} structure.