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

Side by Side Diff: runtime/bin/file_win.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_macos.cc ('k') | tests/standalone/src/FileTest.dart » ('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 <fcntl.h> 5 #include <fcntl.h>
6 #include <io.h> 6 #include <io.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return write(handle_->fd(), buffer, num_bytes); 62 return write(handle_->fd(), buffer, num_bytes);
63 } 63 }
64 64
65 65
66 off_t File::Position() { 66 off_t File::Position() {
67 ASSERT(handle_->fd() >= 0); 67 ASSERT(handle_->fd() >= 0);
68 return lseek(handle_->fd(), 0, SEEK_CUR); 68 return lseek(handle_->fd(), 0, SEEK_CUR);
69 } 69 }
70 70
71 71
72 off_t File::SetPosition(int64_t position) { 72 bool File::SetPosition(int64_t position) {
73 ASSERT(handle_->fd() >= 0); 73 ASSERT(handle_->fd() >= 0);
74 return lseek(handle_->fd(), position, SEEK_SET); 74 return (lseek(handle_->fd(), position, SEEK_SET) != -1);
75 } 75 }
76 76
77 77
78 bool File::Truncate(int64_t length) {
79 ASSERT(handle_->fd() >= 0);
80 return (chsize(handle_->fd(), length) != -1);
81 }
82
83
78 void File::Flush() { 84 void File::Flush() {
79 ASSERT(handle_->fd()); 85 ASSERT(handle_->fd());
80 _commit(handle_->fd()); 86 _commit(handle_->fd());
81 } 87 }
82 88
83 89
84 off_t File::Length() { 90 off_t File::Length() {
85 ASSERT(handle_->fd() >= 0); 91 ASSERT(handle_->fd() >= 0);
86 off_t position = lseek(handle_->fd(), 0, SEEK_CUR); 92 off_t position = lseek(handle_->fd(), 0, SEEK_CUR);
87 if (position < 0) { 93 if (position < 0) {
(...skipping 66 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_macos.cc ('k') | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698