Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: base/platform_file_posix.cc

Issue 13818027: posix: replace nonstandard futimes call with futimens (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo stray changes to time_unittest.cc Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698