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

Side by Side Diff: runtime/bin/file_linux.cc

Issue 8679005: Add truncate operation to File API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <libgen.h> 9 #include <libgen.h>
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return write(handle_->fd(), buffer, num_bytes); 65 return write(handle_->fd(), buffer, num_bytes);
66 } 66 }
67 67
68 68
69 off_t File::Position() { 69 off_t File::Position() {
70 ASSERT(handle_->fd() >= 0); 70 ASSERT(handle_->fd() >= 0);
71 return lseek(handle_->fd(), 0, SEEK_CUR); 71 return lseek(handle_->fd(), 0, SEEK_CUR);
72 } 72 }
73 73
74 74
75 off_t File::SetPosition(int64_t position) { 75 bool File::SetPosition(int64_t position) {
76 ASSERT(handle_->fd() >= 0); 76 ASSERT(handle_->fd() >= 0);
77 return lseek(handle_->fd(), position, SEEK_SET); 77 return (lseek(handle_->fd(), position, SEEK_SET) != -1);
78 } 78 }
79 79
80 80
81 bool File::Truncate(int64_t length) {
82 ASSERT(handle_->fd() >= 0);
83 return (ftruncate(handle_->fd(), length) != -1);
84 }
85
86
81 void File::Flush() { 87 void File::Flush() {
82 ASSERT(handle_->fd() >= 0); 88 ASSERT(handle_->fd() >= 0);
83 fsync(handle_->fd()); 89 fsync(handle_->fd());
84 } 90 }
85 91
86 92
87 off_t File::Length() { 93 off_t File::Length() {
88 ASSERT(handle_->fd() >= 0); 94 ASSERT(handle_->fd() >= 0);
89 off_t position = lseek(handle_->fd(), 0, SEEK_CUR); 95 off_t position = lseek(handle_->fd(), 0, SEEK_CUR);
90 if (position < 0) { 96 if (position < 0) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 160
155 161
156 const char* File::PathSeparator() { 162 const char* File::PathSeparator() {
157 return "/"; 163 return "/";
158 } 164 }
159 165
160 166
161 const char* File::StringEscapedPathSeparator() { 167 const char* File::StringEscapedPathSeparator() {
162 return "/"; 168 return "/";
163 } 169 }
OLDNEW
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698