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/files/file.h" | 5 #include "base/files/file.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ts_times[1].tv_nsec = times[1].tv_usec * 1000; | 63 ts_times[1].tv_nsec = times[1].tv_usec * 1000; |
64 | 64 |
65 return futimens(file, ts_times); | 65 return futimens(file, ts_times); |
66 #else | 66 #else |
67 return futimes(file, times); | 67 return futimes(file, times); |
68 #endif | 68 #endif |
69 } | 69 } |
70 | 70 |
71 File::Error CallFcntlFlock(PlatformFile file, bool do_lock) { | 71 File::Error CallFcntlFlock(PlatformFile file, bool do_lock) { |
72 struct flock lock; | 72 struct flock lock; |
73 lock.l_type = F_WRLCK; | 73 lock.l_type = do_lock ? F_WRLCK : F_UNLCK; |
74 lock.l_whence = SEEK_SET; | 74 lock.l_whence = SEEK_SET; |
75 lock.l_start = 0; | 75 lock.l_start = 0; |
76 lock.l_len = 0; // Lock entire file. | 76 lock.l_len = 0; // Lock entire file. |
77 if (HANDLE_EINTR(fcntl(file, do_lock ? F_SETLK : F_UNLCK, &lock)) == -1) | 77 if (HANDLE_EINTR(fcntl(file, F_SETLK, &lock)) == -1) |
78 return File::OSErrorToFileError(errno); | 78 return File::OSErrorToFileError(errno); |
79 return File::FILE_OK; | 79 return File::FILE_OK; |
80 } | 80 } |
81 #else // defined(OS_NACL) | 81 #else // defined(OS_NACL) |
82 | 82 |
83 bool IsOpenAppend(PlatformFile file) { | 83 bool IsOpenAppend(PlatformFile file) { |
84 // NaCl doesn't implement fcntl. Since NaCl's write conforms to the POSIX | 84 // NaCl doesn't implement fcntl. Since NaCl's write conforms to the POSIX |
85 // standard and always appends if the file is opened with O_APPEND, just | 85 // standard and always appends if the file is opened with O_APPEND, just |
86 // return false here. | 86 // return false here. |
87 return false; | 87 return false; |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 return !HANDLE_EINTR(fsync(file_.get())); | 522 return !HANDLE_EINTR(fsync(file_.get())); |
523 #endif | 523 #endif |
524 } | 524 } |
525 | 525 |
526 void File::SetPlatformFile(PlatformFile file) { | 526 void File::SetPlatformFile(PlatformFile file) { |
527 DCHECK(!file_.is_valid()); | 527 DCHECK(!file_.is_valid()); |
528 file_.reset(file); | 528 file_.reset(file); |
529 } | 529 } |
530 | 530 |
531 } // namespace base | 531 } // namespace base |
OLD | NEW |