1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* stat-related time functions.
5 Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Written by Paul Eggert. */
28 /* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
29 struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
30 ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
31 if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
32 for access, status change, data modification, or birth (creation)
35 These macros are private to stat-time.h. */
36 #if defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
37 # ifdef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
38 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
40 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
42 #elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
43 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
44 #elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
45 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
46 #elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
47 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
50 /* Return the nanosecond component of *ST's access time. */
51 static inline long int
52 get_stat_atime_ns (struct stat const *st)
54 # if defined STAT_TIMESPEC
55 return STAT_TIMESPEC (st, st_atim).tv_nsec;
56 # elif defined STAT_TIMESPEC_NS
57 return STAT_TIMESPEC_NS (st, st_atim);
63 /* Return the nanosecond component of *ST's status change time. */
64 static inline long int
65 get_stat_ctime_ns (struct stat const *st)
67 # if defined STAT_TIMESPEC
68 return STAT_TIMESPEC (st, st_ctim).tv_nsec;
69 # elif defined STAT_TIMESPEC_NS
70 return STAT_TIMESPEC_NS (st, st_ctim);
76 /* Return the nanosecond component of *ST's data modification time. */
77 static inline long int
78 get_stat_mtime_ns (struct stat const *st)
80 # if defined STAT_TIMESPEC
81 return STAT_TIMESPEC (st, st_mtim).tv_nsec;
82 # elif defined STAT_TIMESPEC_NS
83 return STAT_TIMESPEC_NS (st, st_mtim);
89 /* Return the nanosecond component of *ST's birth time. */
90 static inline long int
91 get_stat_birthtime_ns (struct stat const *st)
93 # if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
94 return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
95 # elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
96 return STAT_TIMESPEC_NS (st, st_birthtim);
98 /* Avoid a "parameter unused" warning. */
104 /* Return *ST's access time. */
105 static inline struct timespec
106 get_stat_atime (struct stat const *st)
109 return STAT_TIMESPEC (st, st_atim);
112 t.tv_sec = st->st_atime;
113 t.tv_nsec = get_stat_atime_ns (st);
118 /* Return *ST's status change time. */
119 static inline struct timespec
120 get_stat_ctime (struct stat const *st)
123 return STAT_TIMESPEC (st, st_ctim);
126 t.tv_sec = st->st_ctime;
127 t.tv_nsec = get_stat_ctime_ns (st);
132 /* Return *ST's data modification time. */
133 static inline struct timespec
134 get_stat_mtime (struct stat const *st)
137 return STAT_TIMESPEC (st, st_mtim);
140 t.tv_sec = st->st_mtime;
141 t.tv_nsec = get_stat_mtime_ns (st);
146 /* Return *ST's birth time, if available; otherwise return a value
147 with negative tv_nsec. */
148 static inline struct timespec
149 get_stat_birthtime (struct stat const *st)
153 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
154 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
155 t = STAT_TIMESPEC (st, st_birthtim);
156 #elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
157 t.tv_sec = st->st_birthtime;
158 t.tv_nsec = st->st_birthtimensec;
159 #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
160 /* Woe32 native platforms (but not Cygwin) put the "file creation
161 time" in st_ctime (!). See
162 <http://msdn2.microsoft.com/de-de/library/14h5k7ff(VS.80).aspx>. */
163 t.tv_sec = st->st_ctime;
166 /* Birth time is not supported. Set tv_sec to avoid undefined behavior. */
169 /* Avoid a "parameter unused" warning. */
173 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
174 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
175 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
176 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by
177 using zero. Attempt to work around this problem. Alas, this can
178 report failure even for valid time stamps. Also, NetBSD
179 sometimes returns junk in the birth time fields; work around this
180 bug if it it is detected. There's no need to detect negative
181 tv_nsec junk as negative tv_nsec already indicates an error. */
182 if (t.tv_sec == 0 || 1000000000 <= t.tv_nsec)