summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-09-09 14:24:16 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-09-09 14:24:16 (GMT)
commit94717ed1d4e8c361656cfdfa16ccc3364073cde8 (patch)
tree92375465d0300e79d6d6d815d919e6a4efcb4f78
parentdf453fd02650913a081d7b9403e62bbbabc9d29b (diff)
downloadcpython-94717ed1d4e8c361656cfdfa16ccc3364073cde8.zip
cpython-94717ed1d4e8c361656cfdfa16ccc3364073cde8.tar.gz
cpython-94717ed1d4e8c361656cfdfa16ccc3364073cde8.tar.bz2
Patch #606592: Subsecond timestamps in stat_result.
-rw-r--r--Doc/lib/libos.tex3
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/posixmodule.c36
-rwxr-xr-xconfigure61
-rw-r--r--configure.in17
-rw-r--r--pyconfig.h.in3
6 files changed, 112 insertions, 11 deletions
diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex
index fb53b17..b1adc1b 100644
--- a/Doc/lib/libos.tex
+++ b/Doc/lib/libos.tex
@@ -859,6 +859,9 @@ order
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.
diff --git a/Misc/NEWS b/Misc/NEWS
index d08bc34..4e0c319 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -274,6 +274,9 @@ Core and builtins
Extension modules
+- The time stamps in os.stat_result are floating point numbers now if
+ the system supports that.
+
- If the size passed to mmap.mmap() is larger than the length of the
file on non-Windows platforms, a ValueError is raised. [SF bug 585792]
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 9885b14..6124400 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -612,11 +612,28 @@ static PyStructSequence_Desc statvfs_result_desc = {
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 @@ _pystat_fromstructstat(STRUCT_STAT st)
#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,
diff --git a/configure b/configure
index f45cb17..ecd0828 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 1.339 .
+# From configure.in Revision: 1.341 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.53.
#
@@ -15699,6 +15699,65 @@ _ACEOF
fi
+# Look for subsecond timestamps in struct stat
+echo "$as_me:$LINENO: checking for tv_nsec in struct stat" >&5
+echo $ECHO_N "checking for tv_nsec in struct stat... $ECHO_C" >&6
+if test "${ac_cv_stat_tv_nsec+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <sys/stat.h>
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+struct stat st;
+st.st_mtim.tv_nsec = 1;
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_stat_tv_nsec = yes
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_stat_tv_nsec=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+
+echo "$as_me:$LINENO: result: $ac_cv_stat_tv_nsec" >&5
+echo "${ECHO_T}$ac_cv_stat_tv_nsec" >&6
+if test "$ac_cv_stat_tv_nsec" = yes
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_STAT_TV_NSEC 1
+_ACEOF
+
+fi
+
# On HP/UX 11.0, mvwdelch is a block with a return statement
echo "$as_me:$LINENO: checking whether mvwdelch is an expression" >&5
echo $ECHO_N "checking whether mvwdelch is an expression... $ECHO_C" >&6
diff --git a/configure.in b/configure.in
index ba5fee2..57924e8 100644
--- a/configure.in
+++ b/configure.in
@@ -2240,6 +2240,23 @@ then
[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 <sys/stat.h>], [
+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,
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 74625f2..d664860 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -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 <stdarg.h> header file. */
#undef HAVE_STDARG_H