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

Unified Diff: runtime/bin/file_linux.cc

Issue 10065013: Support length operation without opening file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix error message and fix Windows port 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_linux.cc
diff --git a/runtime/bin/file_linux.cc b/runtime/bin/file_linux.cc
index f04234fbea7a6ef9e3743ebf2324052456605c62..03dd50a1077758f4cf2f0058dbe35640f819bf23 100644
--- a/runtime/bin/file_linux.cc
+++ b/runtime/bin/file_linux.cc
@@ -93,14 +93,11 @@ bool File::Flush() {
off_t File::Length() {
ASSERT(handle_->fd() >= 0);
- off_t position = TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_CUR));
- if (position < 0) {
- // The file is not capable of seeking. Return an error.
- return -1;
+ struct stat st;
+ if (TEMP_FAILURE_RETRY(fstat(handle_->fd(), &st)) == 0) {
+ return st.st_size;
}
- off_t result = TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_END));
- TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET));
- return result;
+ return -1;
}
@@ -168,6 +165,15 @@ bool File::Delete(const char* name) {
}
+off_t File::LengthFromName(const char* name) {
+ struct stat st;
+ if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
+ return st.st_size;
+ }
+ return -1;
+}
+
+
bool File::IsAbsolutePath(const char* pathname) {
return (pathname != NULL && pathname[0] == '/');
}
« 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