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

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

Issue 9072003: Handle reading byte past the end of file (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | 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 "bin/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 9
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { 79 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) {
80 Dart_EnterScope(); 80 Dart_EnterScope();
81 intptr_t return_value = -1; 81 intptr_t return_value = -1;
82 intptr_t value = 82 intptr_t value =
83 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 83 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
84 File* file = reinterpret_cast<File*>(value); 84 File* file = reinterpret_cast<File*>(value);
85 if (file != NULL) { 85 if (file != NULL) {
86 uint8_t buffer; 86 uint8_t buffer;
87 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); 87 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1);
88 if (bytes_read >= 0) { 88 if (bytes_read == 1) {
89 return_value = static_cast<intptr_t>(buffer); 89 return_value = static_cast<intptr_t>(buffer);
90 } else {
91 return_value = -1;
90 } 92 }
91 } 93 }
92 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 94 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
93 Dart_ExitScope(); 95 Dart_ExitScope();
94 } 96 }
95 97
96 98
97 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { 99 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) {
98 Dart_EnterScope(); 100 Dart_EnterScope();
99 intptr_t return_value = -1; 101 intptr_t return_value = -1;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 Dart_EnterScope(); 303 Dart_EnterScope();
302 const char* str = 304 const char* str =
303 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 305 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
304 char* path = File::GetCanonicalPath(str); 306 char* path = File::GetCanonicalPath(str);
305 if (path != NULL) { 307 if (path != NULL) {
306 Dart_SetReturnValue(args, Dart_NewString(path)); 308 Dart_SetReturnValue(args, Dart_NewString(path));
307 free(path); 309 free(path);
308 } 310 }
309 Dart_ExitScope(); 311 Dart_ExitScope();
310 } 312 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698