| 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 struct flock fl; |
| 117 switch (lock) { |
| 118 case File::kLockUnlock: |
| 119 fl.l_type = F_UNLCK; |
| 120 break; |
| 121 case File::kLockShared: |
| 122 fl.l_type = F_RDLCK; |
| 123 break; |
| 124 case File::kLockExclusive: |
| 125 fl.l_type = F_WRLCK; |
| 126 break; |
| 127 default: |
| 128 return false; |
| 129 } |
| 130 fl.l_whence = SEEK_SET; |
| 131 fl.l_start = start; |
| 132 fl.l_len = end == -1 ? 0 : end - start; |
| 133 int rc = fcntl(handle_->fd(), F_SETLK, &fl); |
| 134 return rc != -1; |
| 135 } |
| 136 |
| 137 |
| 114 int64_t File::Length() { | 138 int64_t File::Length() { |
| 115 ASSERT(handle_->fd() >= 0); | 139 ASSERT(handle_->fd() >= 0); |
| 116 struct stat st; | 140 struct stat st; |
| 117 if (NO_RETRY_EXPECTED(fstat(handle_->fd(), &st)) == 0) { | 141 if (NO_RETRY_EXPECTED(fstat(handle_->fd(), &st)) == 0) { |
| 118 return st.st_size; | 142 return st.st_size; |
| 119 } | 143 } |
| 120 return -1; | 144 return -1; |
| 121 } | 145 } |
| 122 | 146 |
| 123 | 147 |
| (...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 && | 416 return (file_1_info.st_ino == file_2_info.st_ino && |
| 393 file_1_info.st_dev == file_2_info.st_dev) ? | 417 file_1_info.st_dev == file_2_info.st_dev) ? |
| 394 File::kIdentical : | 418 File::kIdentical : |
| 395 File::kDifferent; | 419 File::kDifferent; |
| 396 } | 420 } |
| 397 | 421 |
| 398 } // namespace bin | 422 } // namespace bin |
| 399 } // namespace dart | 423 } // namespace dart |
| 400 | 424 |
| 401 #endif // defined(TARGET_OS_MACOS) | 425 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |