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

Unified Diff: runtime/bin/file_macos.cc

Issue 833623004: Add support for file locking (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows test Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/file_macos.cc
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc
index 830b3c408e81a344f83af0a08075bf140811d8e6..ce3b5f42ca27fa2f682abfe75b4859c35e93ce63 100644
--- a/runtime/bin/file_macos.cc
+++ b/runtime/bin/file_macos.cc
@@ -111,6 +111,32 @@ bool File::Flush() {
}
+bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
+ ASSERT(handle_->fd() >= 0);
+ ASSERT(end == -1 || end > start);
+ struct flock fl;
+ switch (lock) {
+ case File::kLockUnlock:
+ fl.l_type = F_UNLCK;
+ break;
+ case File::kLockShared:
+ fl.l_type = F_RDLCK;
+ break;
+ case File::kLockExclusive:
+ fl.l_type = F_WRLCK;
+ break;
+ default:
+ return false;
+ }
+ fl.l_whence = SEEK_SET;
+ fl.l_start = start;
+ fl.l_len = end == -1 ? 0 : end - start;
+ // fcntl does not block, but fails if the lock cannot be acquired.
+ int rc = fcntl(handle_->fd(), F_SETLK, &fl);
+ return rc != -1;
+}
+
+
int64_t File::Length() {
ASSERT(handle_->fd() >= 0);
struct stat st;
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/file_patch.dart » ('j') | sdk/lib/io/file.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698