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

Side by Side Diff: runtime/bin/file_android.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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
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);
kustermann 2015/01/08 12:54:27 ASSERT(end > start);
Søren Gjesse 2015/01/09 13:06:20 Done.
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);
kustermann 2015/01/08 12:54:27 Add a comment that F_SETLK does not block but rath
Søren Gjesse 2015/01/09 13:06:20 Done.
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 return (file_1_info.st_ino == file_2_info.st_ino && 451 return (file_1_info.st_ino == file_2_info.st_ino &&
428 file_1_info.st_dev == file_2_info.st_dev) ? 452 file_1_info.st_dev == file_2_info.st_dev) ?
429 File::kIdentical : 453 File::kIdentical :
430 File::kDifferent; 454 File::kDifferent;
431 } 455 }
432 456
433 } // namespace bin 457 } // namespace bin
434 } // namespace dart 458 } // namespace dart
435 459
436 #endif // defined(TARGET_OS_ANDROID) 460 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698