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

Side by Side Diff: runtime/bin/file_linux.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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1); 102 return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1);
103 } 103 }
104 104
105 105
106 bool File::Flush() { 106 bool File::Flush() {
107 ASSERT(handle_->fd() >= 0); 107 ASSERT(handle_->fd() >= 0);
108 return NO_RETRY_EXPECTED(fsync(handle_->fd())) != -1; 108 return NO_RETRY_EXPECTED(fsync(handle_->fd())) != -1;
109 } 109 }
110 110
111 111
112 bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
113 ASSERT(handle_->fd() >= 0);
114 struct flock fl;
115 switch (lock) {
116 case File::kLockUnlock:
117 fl.l_type = F_UNLCK;
118 break;
119 case File::kLockShared:
120 fl.l_type = F_RDLCK;
121 break;
122 case File::kLockExclusive:
123 fl.l_type = F_WRLCK;
124 break;
125 default:
126 return false;
127 }
128 fl.l_whence = SEEK_SET;
129 fl.l_start = start;
130 fl.l_len = end == -1 ? 0 : end - start;
131 int rc = fcntl(handle_->fd(), F_SETLK, &fl);
132 return rc != -1;
133 }
134
135
112 int64_t File::Length() { 136 int64_t File::Length() {
113 ASSERT(handle_->fd() >= 0); 137 ASSERT(handle_->fd() >= 0);
114 struct stat64 st; 138 struct stat64 st;
115 if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) { 139 if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) {
116 return st.st_size; 140 return st.st_size;
117 } 141 }
118 return -1; 142 return -1;
119 } 143 }
120 144
121 145
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return (file_1_info.st_ino == file_2_info.st_ino && 450 return (file_1_info.st_ino == file_2_info.st_ino &&
427 file_1_info.st_dev == file_2_info.st_dev) ? 451 file_1_info.st_dev == file_2_info.st_dev) ?
428 File::kIdentical : 452 File::kIdentical :
429 File::kDifferent; 453 File::kDifferent;
430 } 454 }
431 455
432 } // namespace bin 456 } // namespace bin
433 } // namespace dart 457 } // namespace dart
434 458
435 #endif // defined(TARGET_OS_LINUX) 459 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698