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-2014 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 #ifndef _GL_INLINE_HEADER_BEGIN
29 #error "Please include config.h first."
31 _GL_INLINE_HEADER_BEGIN
32 #ifndef _GL_STAT_TIME_INLINE
33 # define _GL_STAT_TIME_INLINE _GL_INLINE
36 /* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
37 struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
38 ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
39 if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
40 for access, status change, data modification, or birth (creation)
43 These macros are private to stat-time.h. */
44 #if defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
45 # ifdef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
46 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
48 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
50 #elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
51 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
52 #elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
53 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
54 #elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
55 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
58 /* Return the nanosecond component of *ST's access time. */
59 _GL_STAT_TIME_INLINE long int
60 get_stat_atime_ns (struct stat const *st)
62 # if defined STAT_TIMESPEC
63 return STAT_TIMESPEC (st, st_atim).tv_nsec;
64 # elif defined STAT_TIMESPEC_NS
65 return STAT_TIMESPEC_NS (st, st_atim);
71 /* Return the nanosecond component of *ST's status change time. */
72 _GL_STAT_TIME_INLINE long int
73 get_stat_ctime_ns (struct stat const *st)
75 # if defined STAT_TIMESPEC
76 return STAT_TIMESPEC (st, st_ctim).tv_nsec;
77 # elif defined STAT_TIMESPEC_NS
78 return STAT_TIMESPEC_NS (st, st_ctim);
84 /* Return the nanosecond component of *ST's data modification time. */
85 _GL_STAT_TIME_INLINE long int
86 get_stat_mtime_ns (struct stat const *st)
88 # if defined STAT_TIMESPEC
89 return STAT_TIMESPEC (st, st_mtim).tv_nsec;
90 # elif defined STAT_TIMESPEC_NS
91 return STAT_TIMESPEC_NS (st, st_mtim);
97 /* Return the nanosecond component of *ST's birth time. */
98 _GL_STAT_TIME_INLINE long int
99 get_stat_birthtime_ns (struct stat const *st)
101 # if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
102 return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
103 # elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
104 return STAT_TIMESPEC_NS (st, st_birthtim);
106 /* Avoid a "parameter unused" warning. */
112 /* Return *ST's access time. */
113 _GL_STAT_TIME_INLINE struct timespec
114 get_stat_atime (struct stat const *st)
117 return STAT_TIMESPEC (st, st_atim);
120 t.tv_sec = st->st_atime;
121 t.tv_nsec = get_stat_atime_ns (st);
126 /* Return *ST's status change time. */
127 _GL_STAT_TIME_INLINE struct timespec
128 get_stat_ctime (struct stat const *st)
131 return STAT_TIMESPEC (st, st_ctim);
134 t.tv_sec = st->st_ctime;
135 t.tv_nsec = get_stat_ctime_ns (st);
140 /* Return *ST's data modification time. */
141 _GL_STAT_TIME_INLINE struct timespec
142 get_stat_mtime (struct stat const *st)
145 return STAT_TIMESPEC (st, st_mtim);
148 t.tv_sec = st->st_mtime;
149 t.tv_nsec = get_stat_mtime_ns (st);
154 /* Return *ST's birth time, if available; otherwise return a value
155 with tv_sec and tv_nsec both equal to -1. */
156 _GL_STAT_TIME_INLINE struct timespec
157 get_stat_birthtime (struct stat const *st)
161 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
162 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
163 t = STAT_TIMESPEC (st, st_birthtim);
164 #elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
165 t.tv_sec = st->st_birthtime;
166 t.tv_nsec = st->st_birthtimensec;
167 #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
168 /* Native Windows platforms (but not Cygwin) put the "file creation
169 time" in st_ctime (!). See
170 <http://msdn2.microsoft.com/de-de/library/14h5k7ff(VS.80).aspx>. */
171 t.tv_sec = st->st_ctime;
174 /* Birth time is not supported. */
177 /* Avoid a "parameter unused" warning. */
181 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
182 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
183 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
184 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by
185 using zero. Attempt to work around this problem. Alas, this can
186 report failure even for valid time stamps. Also, NetBSD
187 sometimes returns junk in the birth time fields; work around this
188 bug if it is detected. */
189 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
199 _GL_INLINE_HEADER_END