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

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: Comment/doc fixes 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..eb0dc0c8fa3ce2c27c715d47cd5abe3ed92cf8a9 100644
--- a/runtime/bin/file_macos.cc
+++ b/runtime/bin/file_macos.cc
@@ -111,6 +111,30 @@ bool File::Flush() {
}
+bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
+ ASSERT(handle_->fd() >= 0);
+ 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;
+ int rc = fcntl(handle_->fd(), F_SETLK, &fl);
+ return rc != -1;
+}
+
+
int64_t File::Length() {
ASSERT(handle_->fd() >= 0);
struct stat st;

Powered by Google App Engine
This is Rietveld 408576698