Lines 96-115
Link Here
|
96 |
#endif |
96 |
#endif |
97 |
|
97 |
|
98 |
/* POSIX 200x added two interfaces to set file timestamps with |
98 |
/* POSIX 200x added two interfaces to set file timestamps with |
99 |
nanosecond resolution. */ |
99 |
nanosecond resolution. We provide a fallback for ENOSYS (for |
|
|
100 |
example, compiling against Linux 2.6.25 kernel headers and glibc |
101 |
2.7, but running on Linux 2.6.18 kernel). */ |
100 |
#if HAVE_UTIMENSAT |
102 |
#if HAVE_UTIMENSAT |
101 |
if (fd < 0) |
103 |
if (fd < 0) |
102 |
return utimensat (AT_FDCWD, file, timespec, 0); |
104 |
{ |
|
|
105 |
int result = utimensat (AT_FDCWD, file, timespec, 0); |
106 |
if (result == 0 || errno != ENOSYS) |
107 |
return result; |
108 |
} |
103 |
#endif |
109 |
#endif |
104 |
#if HAVE_FUTIMENS |
110 |
#if HAVE_FUTIMENS |
105 |
return futimens (fd, timespec); |
111 |
{ |
106 |
#else |
112 |
int result = futimens (fd, timespec); |
|
|
113 |
if (result == 0 || errno != ENOSYS) |
114 |
return result; |
115 |
} |
116 |
#endif |
107 |
|
117 |
|
108 |
/* The platform lacks an interface to set file timestamps with |
118 |
/* The platform lacks an interface to set file timestamps with |
109 |
nanosecond resolution, so do the best we can, discarding any |
119 |
nanosecond resolution, so do the best we can, discarding any |
110 |
fractional part of the timestamp. */ |
120 |
fractional part of the timestamp. */ |
111 |
{ |
121 |
{ |
112 |
# if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES |
122 |
#if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES |
113 |
struct timeval timeval[2]; |
123 |
struct timeval timeval[2]; |
114 |
struct timeval const *t; |
124 |
struct timeval const *t; |
115 |
if (timespec) |
125 |
if (timespec) |
Lines 125-133
Link Here
|
125 |
|
135 |
|
126 |
if (fd < 0) |
136 |
if (fd < 0) |
127 |
{ |
137 |
{ |
128 |
# if HAVE_FUTIMESAT |
138 |
# if HAVE_FUTIMESAT |
129 |
return futimesat (AT_FDCWD, file, t); |
139 |
return futimesat (AT_FDCWD, file, t); |
130 |
# endif |
140 |
# endif |
131 |
} |
141 |
} |
132 |
else |
142 |
else |
133 |
{ |
143 |
{ |
Lines 141-161
Link Here
|
141 |
worth optimizing, and who knows what other messed-up systems |
151 |
worth optimizing, and who knows what other messed-up systems |
142 |
are out there? So play it safe and fall back on the code |
152 |
are out there? So play it safe and fall back on the code |
143 |
below. */ |
153 |
below. */ |
144 |
# if HAVE_FUTIMESAT |
154 |
# if HAVE_FUTIMESAT |
145 |
if (futimesat (fd, NULL, t) == 0) |
155 |
if (futimesat (fd, NULL, t) == 0) |
146 |
return 0; |
156 |
return 0; |
147 |
# elif HAVE_FUTIMES |
157 |
# elif HAVE_FUTIMES |
148 |
if (futimes (fd, t) == 0) |
158 |
if (futimes (fd, t) == 0) |
149 |
return 0; |
159 |
return 0; |
150 |
# endif |
160 |
# endif |
151 |
} |
161 |
} |
152 |
# endif /* HAVE_FUTIMESAT || HAVE_WORKING_UTIMES */ |
162 |
#endif /* HAVE_FUTIMESAT || HAVE_WORKING_UTIMES */ |
153 |
|
163 |
|
154 |
if (!file) |
164 |
if (!file) |
155 |
{ |
165 |
{ |
156 |
# if ! (HAVE_FUTIMESAT || (HAVE_WORKING_UTIMES && HAVE_FUTIMES)) |
166 |
#if ! (HAVE_FUTIMESAT || (HAVE_WORKING_UTIMES && HAVE_FUTIMES)) |
157 |
errno = ENOSYS; |
167 |
errno = ENOSYS; |
158 |
# endif |
168 |
#endif |
159 |
|
169 |
|
160 |
/* Prefer EBADF to ENOSYS if both error numbers apply. */ |
170 |
/* Prefer EBADF to ENOSYS if both error numbers apply. */ |
161 |
if (errno == ENOSYS) |
171 |
if (errno == ENOSYS) |
Lines 170-178
Link Here
|
170 |
return -1; |
180 |
return -1; |
171 |
} |
181 |
} |
172 |
|
182 |
|
173 |
# if HAVE_WORKING_UTIMES |
183 |
#if HAVE_WORKING_UTIMES |
174 |
return utimes (file, t); |
184 |
return utimes (file, t); |
175 |
# else |
185 |
#else |
176 |
{ |
186 |
{ |
177 |
struct utimbuf utimbuf; |
187 |
struct utimbuf utimbuf; |
178 |
struct utimbuf const *ut; |
188 |
struct utimbuf const *ut; |
Lines 187-195
Link Here
|
187 |
|
197 |
|
188 |
return utime (file, ut); |
198 |
return utime (file, ut); |
189 |
} |
199 |
} |
190 |
# endif /* !HAVE_WORKING_UTIMES */ |
200 |
#endif /* !HAVE_WORKING_UTIMES */ |
191 |
} |
201 |
} |
192 |
#endif /* !HAVE_FUTIMENS */ |
|
|
193 |
} |
202 |
} |
194 |
|
203 |
|
195 |
/* Set the access and modification time stamps of FILE to be |
204 |
/* Set the access and modification time stamps of FILE to be |