OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/platform_file.h" | 5 #include "base/platform_file.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 294 |
295 bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time, | 295 bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time, |
296 const base::Time& last_modified_time) { | 296 const base::Time& last_modified_time) { |
297 base::ThreadRestrictions::AssertIOAllowed(); | 297 base::ThreadRestrictions::AssertIOAllowed(); |
298 if (file < 0) | 298 if (file < 0) |
299 return false; | 299 return false; |
300 | 300 |
301 timeval times[2]; | 301 timeval times[2]; |
302 times[0] = last_access_time.ToTimeVal(); | 302 times[0] = last_access_time.ToTimeVal(); |
303 times[1] = last_modified_time.ToTimeVal(); | 303 times[1] = last_modified_time.ToTimeVal(); |
| 304 |
| 305 #ifdef __USE_XOPEN2K8 |
| 306 // futimens should be available, but futimes might not be |
| 307 // http://pubs.opengroup.org/onlinepubs/9699919799/ |
| 308 |
| 309 timespec ts_times[2]; |
| 310 ts_times[0].tv_sec = times[0].tv_sec; |
| 311 ts_times[0].tv_nsec = times[0].tv_usec * 1000; |
| 312 ts_times[1].tv_sec = times[1].tv_sec; |
| 313 ts_times[1].tv_nsec = times[1].tv_usec * 1000; |
| 314 |
| 315 return !futimens(file, ts_times); |
| 316 #else |
304 return !futimes(file, times); | 317 return !futimes(file, times); |
| 318 #endif |
305 } | 319 } |
306 | 320 |
307 bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) { | 321 bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) { |
308 if (!info) | 322 if (!info) |
309 return false; | 323 return false; |
310 | 324 |
311 stat_wrapper_t file_info; | 325 stat_wrapper_t file_info; |
312 if (CallFstat(file, &file_info)) | 326 if (CallFstat(file, &file_info)) |
313 return false; | 327 return false; |
314 | 328 |
315 info->is_directory = S_ISDIR(file_info.st_mode); | 329 info->is_directory = S_ISDIR(file_info.st_mode); |
316 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 330 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
317 info->size = file_info.st_size; | 331 info->size = file_info.st_size; |
318 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 332 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
319 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 333 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
320 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 334 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
321 return true; | 335 return true; |
322 } | 336 } |
323 | 337 |
324 } // namespace base | 338 } // namespace base |
OLD | NEW |