| 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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 return (file_1_info.st_ino == file_2_info.st_ino && | 418 return (file_1_info.st_ino == file_2_info.st_ino && |
| 393 file_1_info.st_dev == file_2_info.st_dev) ? | 419 file_1_info.st_dev == file_2_info.st_dev) ? |
| 394 File::kIdentical : | 420 File::kIdentical : |
| 395 File::kDifferent; | 421 File::kDifferent; |
| 396 } | 422 } |
| 397 | 423 |
| 398 } // namespace bin | 424 } // namespace bin |
| 399 } // namespace dart | 425 } // namespace dart |
| 400 | 426 |
| 401 #endif // defined(TARGET_OS_MACOS) | 427 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |