X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstat-time.h;h=649c848732bd8b184f39b08989ed7b11c7ca420c;hb=fa662f811f9a6dda54f64639b107b1637c3ba2e5;hp=5fd18c1fac094dae47bbd02a3843415646089944;hpb=0e698b54a2d85bddf2bb04ecb60435da4b1bcf11;p=gnulib.git diff --git a/lib/stat-time.h b/lib/stat-time.h index 5fd18c1fa..649c84873 100644 --- a/lib/stat-time.h +++ b/lib/stat-time.h @@ -21,13 +21,15 @@ #ifndef STAT_TIME_H #define STAT_TIME_H 1 +#include #include /* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST, ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST, - if available. ST_XTIM can be st_atim, st_ctim, or st_mtim for - access, status change, or data modification time, respectively. + if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim + for access, status change, data modification, or birth (creation) + time respectively. These macros are private to stat-time.h. */ #if defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC @@ -52,8 +54,6 @@ get_stat_atime_ns (struct stat const *st) return STAT_TIMESPEC (st, st_atim).tv_nsec; # elif defined STAT_TIMESPEC_NS return STAT_TIMESPEC_NS (st, st_atim); -# elif defined HAVE_STRUCT_STAT_ST_SPARE1 - return st->st_spare1 * 1000; # else return 0; # endif @@ -67,8 +67,6 @@ get_stat_ctime_ns (struct stat const *st) return STAT_TIMESPEC (st, st_ctim).tv_nsec; # elif defined STAT_TIMESPEC_NS return STAT_TIMESPEC_NS (st, st_ctim); -# elif defined HAVE_STRUCT_STAT_ST_SPARE1 - return st->st_spare3 * 1000; # else return 0; # endif @@ -82,8 +80,19 @@ get_stat_mtime_ns (struct stat const *st) return STAT_TIMESPEC (st, st_mtim).tv_nsec; # elif defined STAT_TIMESPEC_NS return STAT_TIMESPEC_NS (st, st_mtim); -# elif defined HAVE_STRUCT_STAT_ST_SPARE1 - return st->st_spare2 * 1000; +# else + return 0; +# endif +} + +/* Return the nanosecond component of *ST's birth time. */ +static inline long int +get_stat_birthtime_ns (struct stat const *st) +{ +# if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC + return STAT_TIMESPEC (st, st_birthtim).tv_nsec; +# elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC + return STAT_TIMESPEC_NS (st, st_birthtim); # else return 0; # endif @@ -131,4 +140,45 @@ get_stat_mtime (struct stat const *st) #endif } +/* Return *ST's birth time, if available; otherwise return a value + with negative tv_nsec. */ +static inline struct timespec +get_stat_birthtime (struct stat const *st) +{ + struct timespec t; + +#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \ + || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC) + t = STAT_TIMESPEC (st, st_birthtim); +#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC + t.tv_sec = st->st_birthtime; + t.tv_nsec = st->st_birthtimensec; +#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* Woe32 native platforms (but not Cygwin) put the "file creation + time" in st_ctime (!). See + . */ + t.tv_sec = st->st_ctime; + t.tv_nsec = 0; +#else + /* Birth time is not supported. Set tv_sec to avoid undefined behavior. */ + t.tv_sec = -1; + t.tv_nsec = -1; +#endif + +#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \ + || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \ + || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC) + /* FreeBSD and NetBSD sometimes signal the absence of knowledge by + using zero. Attempt to work around this problem. Alas, this can + report failure even for valid time stamps. Also, NetBSD + sometimes returns junk in the birth time fields; work around this + bug if it it is detected. There's no need to detect negative + tv_nsec junk as negative tv_nsec already indicates an error. */ + if (t.tv_sec == 0 || 1000000000 <= t.tv_nsec) + t.tv_nsec = -1; +#endif + + return t; +} + #endif