X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstat-time.h;h=86d9d4b8f7be5dfc4686103672d10fb4fde46b0a;hb=4cf71a8c15b38ca98e8b6aef03fe64dfbba51492;hp=ffad8a1fc17f876d67330b9925a90f817b611730;hpb=4202d97c58ffc744a07a667f4d58d4929ab64677;p=gnulib.git diff --git a/lib/stat-time.h b/lib/stat-time.h index ffad8a1fc..86d9d4b8f 100644 --- a/lib/stat-time.h +++ b/lib/stat-time.h @@ -1,11 +1,11 @@ /* stat-related time functions. - Copyright (C) 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -13,8 +13,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* Written by Paul Eggert. */ @@ -94,6 +93,8 @@ get_stat_birthtime_ns (struct stat const *st) # elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC return STAT_TIMESPEC_NS (st, st_birthtim); # else + /* Avoid a "parameter unused" warning. */ + (void) st; return 0; # endif } @@ -141,28 +142,18 @@ get_stat_mtime (struct stat const *st) } /* Return *ST's birth time, if available; otherwise return a value - with negative tv_nsec. */ + with tv_sec and tv_nsec both equal to -1. */ 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 +#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; - - /* NetBSD sometimes signals the absence of knowledge by using zero. - Attempt to work around this bug. This sometimes reports failure - even for valid time stamps. Also, sometimes NetBSD 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; - #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* Woe32 native platforms (but not Cygwin) put the "file creation time" in st_ctime (!). See @@ -170,9 +161,26 @@ get_stat_birthtime (struct stat const *st) t.tv_sec = st->st_ctime; t.tv_nsec = 0; #else - /* Birth time is not supported. Set tv_sec to avoid undefined behavior. */ + /* Birth time is not supported. */ t.tv_sec = -1; t.tv_nsec = -1; + /* Avoid a "parameter unused" warning. */ + (void) st; +#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 is detected. */ + if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000)) + { + t.tv_sec = -1; + t.tv_nsec = -1; + } #endif return t;