Index: runtime/bin/file_android.cc |
diff --git a/runtime/bin/file_android.cc b/runtime/bin/file_android.cc |
index 410fa0fbb84bb58c9996c5b5a1c81f67e6775103..015fc0ad53c013c28a9293709af0ecbdbe313fb0 100644 |
--- a/runtime/bin/file_android.cc |
+++ b/runtime/bin/file_android.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; |