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

Unified Diff: runtime/bin/file.cc

Issue 9034005: Change the behavior of open on files to not truncate by default (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comment.s Created 8 years, 12 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.h ('k') | runtime/bin/file.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file.cc
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
index 2434d1df466e4fe68aeca12287a1ce8b4ccd047f..75e9d9232665eefa961714fc6b3cb026108eef72 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -41,11 +41,25 @@ bool File::WriteFully(const void* buffer, int64_t num_bytes) {
void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
+ // These values have to be kept in sync with the mode values of
+ // FileMode.READ, FileMode.WRITE and FileMode.APPEND in file.dart.
+ static const int kRead = 0;
+ static const int kWrite = 1;
+ static const int kAppend = 2;
+
Dart_EnterScope();
const char* filename =
DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
- bool writable = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1));
- File* file = File::Open(filename, writable);
+ int mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
+ ASSERT(mode == kRead || mode == kWrite || mode == kAppend);
+ File::FileOpenMode file_mode = File::kRead;
+ if (mode == kWrite) {
+ file_mode = File::kWriteTruncate;
+ }
+ if (mode == kAppend) {
+ file_mode = File::kWrite;
+ }
+ File* file = File::Open(filename, file_mode);
Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
Dart_ExitScope();
}
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698