OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1); | 104 return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 bool File::Flush() { | 108 bool File::Flush() { |
109 ASSERT(handle_->fd() >= 0); | 109 ASSERT(handle_->fd() >= 0); |
110 return NO_RETRY_EXPECTED(fsync(handle_->fd()) != -1); | 110 return NO_RETRY_EXPECTED(fsync(handle_->fd()) != -1); |
111 } | 111 } |
112 | 112 |
113 | 113 |
| 114 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
| 115 ASSERT(handle_->fd() >= 0); |
| 116 ASSERT(end == -1 || end > start); |
| 117 struct flock fl; |
| 118 switch (lock) { |
| 119 case File::kLockUnlock: |
| 120 fl.l_type = F_UNLCK; |
| 121 break; |
| 122 case File::kLockShared: |
| 123 fl.l_type = F_RDLCK; |
| 124 break; |
| 125 case File::kLockExclusive: |
| 126 fl.l_type = F_WRLCK; |
| 127 break; |
| 128 default: |
| 129 return false; |
| 130 } |
| 131 fl.l_whence = SEEK_SET; |
| 132 fl.l_start = start; |
| 133 fl.l_len = end == -1 ? 0 : end - start; |
| 134 // fcntl does not block, but fails if the lock cannot be acquired. |
| 135 int rc = fcntl(handle_->fd(), F_SETLK, &fl); |
| 136 return rc != -1; |
| 137 } |
| 138 |
| 139 |
114 int64_t File::Length() { | 140 int64_t File::Length() { |
115 ASSERT(handle_->fd() >= 0); | 141 ASSERT(handle_->fd() >= 0); |
116 struct stat st; | 142 struct stat st; |
117 if (NO_RETRY_EXPECTED(fstat(handle_->fd(), &st)) == 0) { | 143 if (NO_RETRY_EXPECTED(fstat(handle_->fd(), &st)) == 0) { |
118 return st.st_size; | 144 return st.st_size; |
119 } | 145 } |
120 return -1; | 146 return -1; |
121 } | 147 } |
122 | 148 |
123 | 149 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 return (file_1_info.st_ino == file_2_info.st_ino && | 453 return (file_1_info.st_ino == file_2_info.st_ino && |
428 file_1_info.st_dev == file_2_info.st_dev) ? | 454 file_1_info.st_dev == file_2_info.st_dev) ? |
429 File::kIdentical : | 455 File::kIdentical : |
430 File::kDifferent; | 456 File::kDifferent; |
431 } | 457 } |
432 | 458 |
433 } // namespace bin | 459 } // namespace bin |
434 } // namespace dart | 460 } // namespace dart |
435 | 461 |
436 #endif // defined(TARGET_OS_ANDROID) | 462 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |