Mercurial > hg > octave-kai > gnulib-hg
comparison lib/stat-time.h @ 14890:b3af6c2a46e4
stat-time: get_stat_birthtime failure is better-defined
* lib/stat-time.h (get_stat_birthtime): If the time is not available,
return a timestamp whose tv_sec and tv_nsec values are both -1.
Previously, the spec said only that the tv_nsec value was negative.
This upward-compatible change simplifies GNU tar a bit.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 07 Jun 2011 16:01:33 -0700 |
parents | cbd63e66d32f |
children | 8250f2777afc |
comparison
equal
deleted
inserted
replaced
14889:a78ddb38a66b | 14890:b3af6c2a46e4 |
---|---|
140 return t; | 140 return t; |
141 #endif | 141 #endif |
142 } | 142 } |
143 | 143 |
144 /* Return *ST's birth time, if available; otherwise return a value | 144 /* Return *ST's birth time, if available; otherwise return a value |
145 with negative tv_nsec. */ | 145 with tv_sec and tv_nsec both equal to -1. */ |
146 static inline struct timespec | 146 static inline struct timespec |
147 get_stat_birthtime (struct stat const *st) | 147 get_stat_birthtime (struct stat const *st) |
148 { | 148 { |
149 struct timespec t; | 149 struct timespec t; |
150 | 150 |
159 time" in st_ctime (!). See | 159 time" in st_ctime (!). See |
160 <http://msdn2.microsoft.com/de-de/library/14h5k7ff(VS.80).aspx>. */ | 160 <http://msdn2.microsoft.com/de-de/library/14h5k7ff(VS.80).aspx>. */ |
161 t.tv_sec = st->st_ctime; | 161 t.tv_sec = st->st_ctime; |
162 t.tv_nsec = 0; | 162 t.tv_nsec = 0; |
163 #else | 163 #else |
164 /* Birth time is not supported. Set tv_sec to avoid undefined behavior. */ | 164 /* Birth time is not supported. */ |
165 t.tv_sec = -1; | 165 t.tv_sec = -1; |
166 t.tv_nsec = -1; | 166 t.tv_nsec = -1; |
167 /* Avoid a "parameter unused" warning. */ | 167 /* Avoid a "parameter unused" warning. */ |
168 (void) st; | 168 (void) st; |
169 #endif | 169 #endif |
173 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC) | 173 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC) |
174 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by | 174 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by |
175 using zero. Attempt to work around this problem. Alas, this can | 175 using zero. Attempt to work around this problem. Alas, this can |
176 report failure even for valid time stamps. Also, NetBSD | 176 report failure even for valid time stamps. Also, NetBSD |
177 sometimes returns junk in the birth time fields; work around this | 177 sometimes returns junk in the birth time fields; work around this |
178 bug if it is detected. There's no need to detect negative | 178 bug if it is detected. */ |
179 tv_nsec junk as negative tv_nsec already indicates an error. */ | 179 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000)) |
180 if (t.tv_sec == 0 || 1000000000 <= t.tv_nsec) | 180 { |
181 t.tv_nsec = -1; | 181 t.tv_sec = -1; |
182 t.tv_nsec = -1; | |
183 } | |
182 #endif | 184 #endif |
183 | 185 |
184 return t; | 186 return t; |
185 } | 187 } |
186 | 188 |