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

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

Issue 10065013: Support length operation without opening file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 "bin/file.h" 5 #include "bin/file.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <io.h> 8 #include <io.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 84
85 bool File::Flush() { 85 bool File::Flush() {
86 ASSERT(handle_->fd()); 86 ASSERT(handle_->fd());
87 return _commit(handle_->fd()) != -1; 87 return _commit(handle_->fd()) != -1;
88 } 88 }
89 89
90 90
91 off_t File::Length() { 91 off_t File::Length() {
92 ASSERT(handle_->fd() >= 0); 92 ASSERT(handle_->fd() >= 0);
93 off_t position = lseek(handle_->fd(), 0, SEEK_CUR); 93 struct stat st;
94 if (position < 0) { 94 if (TEMP_FAILURE_RETRY(fstat(handle_->fd(), &st)) == 0) {
95 // The file is not capable of seeking. Return an error. 95 return st.st_size;
96 return -1;
97 } 96 }
98 off_t result = lseek(handle_->fd(), 0, SEEK_END); 97 return -1;
99 lseek(handle_->fd(), position, SEEK_SET);
100 return result;
101 } 98 }
102 99
103 100
104 File* File::Open(const char* name, FileOpenMode mode) { 101 File* File::Open(const char* name, FileOpenMode mode) {
105 int flags = O_RDONLY | O_BINARY; 102 int flags = O_RDONLY | O_BINARY;
106 if ((mode & kWrite) != 0) { 103 if ((mode & kWrite) != 0) {
107 flags = (O_RDWR | O_CREAT | O_BINARY); 104 flags = (O_RDWR | O_CREAT | O_BINARY);
108 } 105 }
109 if ((mode & kTruncate) != 0) { 106 if ((mode & kTruncate) != 0) {
110 flags = flags | O_TRUNC; 107 flags = flags | O_TRUNC;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 147
151 bool File::Delete(const char* name) { 148 bool File::Delete(const char* name) {
152 int status = remove(name); 149 int status = remove(name);
153 if (status == -1) { 150 if (status == -1) {
154 return false; 151 return false;
155 } 152 }
156 return true; 153 return true;
157 } 154 }
158 155
159 156
157 off_t File::LengthFromName(const char* name) {
158 struct stat st;
159 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
160 return st.st_size;
161 }
162 return -1;
163 }
164
165
160 bool File::IsAbsolutePath(const char* pathname) { 166 bool File::IsAbsolutePath(const char* pathname) {
161 // Should we consider network paths? 167 // Should we consider network paths?
162 if (pathname == NULL) return false; 168 if (pathname == NULL) return false;
163 return (strlen(pathname) > 2) && 169 return (strlen(pathname) > 2) &&
164 (pathname[1] == ':') && 170 (pathname[1] == ':') &&
165 (pathname[2] == '\\' || pathname[2] == '/'); 171 (pathname[2] == '\\' || pathname[2] == '/');
166 } 172 }
167 173
168 174
169 char* File::GetCanonicalPath(const char* pathname) { 175 char* File::GetCanonicalPath(const char* pathname) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const char* File::StringEscapedPathSeparator() { 218 const char* File::StringEscapedPathSeparator() {
213 return "\\\\"; 219 return "\\\\";
214 } 220 }
215 221
216 222
217 File::StdioHandleType File::GetStdioHandleType(int fd) { 223 File::StdioHandleType File::GetStdioHandleType(int fd) {
218 // Treat all stdio handles as pipes. The Windows event handler and 224 // Treat all stdio handles as pipes. The Windows event handler and
219 // socket code will handle the different handle types. 225 // socket code will handle the different handle types.
220 return kPipe; 226 return kPipe;
221 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698