[Python-Dev] Subsecond time stamps
Martin v. Löwis
loewis@informatik.hu-berlin.de
06 Sep 2002 16:12:25 +0200
A number of systems provide subsecond time stamp resolution for
files. In particular:
- NFS v3 has nanosecond time stamps.
- Solaris 9 has nanosecond time stamps in stat(2), and microsecond
time stamps in utimes(2). In addition, they have microsecond time
stamps on ufs. It appears that other Unices have also extended
stat(2), as does OS X.
- NTFS has 100ns resolution for time stamps.
I'd like to expose atleast the stat extensions to Python. Adding new
fields to stat_result is easy enough, but there are a number of
alternatives:
A. Add an additional field to hold the nanoseconds, i.e. st_mtimensec,
st_atimensec, st_ctimensec. This is the BSD Posix extension.
B. Follow the Unix API (Solaris and others). They define a
struct timespec_t {
time_t tv_sec;
unsigned long tv_nsec;
};
and fields st_mtim, st_ctim, st_atim of timespec_t. For
compatibility, they
#define st_mtime st_mtim.tv_sec
So to get at the seconds, you can write either st_mtim.tv_sec, or
st_mtime. For the nanoseconds, you write st_mtim.tv_nsec.
This requires to add a new type.
C. Make st_mtime a floating point number. This won't offer nanosecond
resolution, as C doubles are not dense enough.
What do you think?
Regards,
Martin