X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fstat-time.h;h=649c848732bd8b184f39b08989ed7b11c7ca420c;hb=800deb09b422a73c1212233a93839a223ff59678;hp=734e366574c49db5c55b838d7166e6bacb42bf58;hpb=0d5a754ba8f2cc33e98d48d559f0ad6cd18a43a3;p=debian%2Fgzip diff --git a/lib/stat-time.h b/lib/stat-time.h index 734e366..649c848 100644 --- a/lib/stat-time.h +++ b/lib/stat-time.h @@ -1,6 +1,6 @@ /* stat-related time functions. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,13 +21,15 @@ #ifndef STAT_TIME_H #define STAT_TIME_H 1 -#include "timespec.h" +#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