Patch #606592: Subsecond timestamps in stat_result.

This commit is contained in:
Martin v. Löwis 2002-09-09 14:24:16 +00:00
parent df453fd026
commit 94717ed1d4
6 changed files with 112 additions and 11 deletions

View File

@ -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.

View File

@ -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]

View File

@ -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,

61
configure vendored
View File

@ -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

View File

@ -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,

View File

@ -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