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

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

Issue 2585443002: Error checking for Stdio calls (Closed)
Patch Set: Fix Windows Created 4 years 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
« no previous file with comments | « runtime/bin/stdio.h ('k') | runtime/bin/stdio_android.cc » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "bin/stdio.h" 7 #include "bin/stdio.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
11 #include "bin/utils.h" 11 #include "bin/utils.h"
12 12
13 #include "include/dart_api.h" 13 #include "include/dart_api.h"
14 14
15 #include "platform/globals.h" 15 #include "platform/globals.h"
16 #include "platform/utils.h" 16 #include "platform/utils.h"
17 17
18 namespace dart { 18 namespace dart {
19 namespace bin { 19 namespace bin {
20 20
21 void FUNCTION_NAME(Stdin_ReadByte)(Dart_NativeArguments args) { 21 void FUNCTION_NAME(Stdin_ReadByte)(Dart_NativeArguments args) {
22 ScopedBlockingCall blocker; 22 ScopedBlockingCall blocker;
23 Dart_SetReturnValue(args, Dart_NewInteger(Stdin::ReadByte())); 23 int byte = -1;
24 if (Stdin::ReadByte(&byte)) {
25 Dart_SetReturnValue(args, Dart_NewInteger(byte));
26 } else {
27 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
28 }
24 } 29 }
25 30
26 31
27 void FUNCTION_NAME(Stdin_GetEchoMode)(Dart_NativeArguments args) { 32 void FUNCTION_NAME(Stdin_GetEchoMode)(Dart_NativeArguments args) {
28 Dart_SetReturnValue(args, Dart_NewBoolean(Stdin::GetEchoMode())); 33 bool enabled = false;
34 if (Stdin::GetEchoMode(&enabled)) {
35 Dart_SetReturnValue(args, Dart_NewBoolean(enabled));
36 } else {
37 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
38 }
29 } 39 }
30 40
31 41
32 void FUNCTION_NAME(Stdin_SetEchoMode)(Dart_NativeArguments args) { 42 void FUNCTION_NAME(Stdin_SetEchoMode)(Dart_NativeArguments args) {
33 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); 43 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0));
34 Stdin::SetEchoMode(enabled); 44 if (Stdin::SetEchoMode(enabled)) {
45 Dart_SetReturnValue(args, Dart_True());
46 } else {
47 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
48 }
35 } 49 }
36 50
37 51
38 void FUNCTION_NAME(Stdin_GetLineMode)(Dart_NativeArguments args) { 52 void FUNCTION_NAME(Stdin_GetLineMode)(Dart_NativeArguments args) {
39 Dart_SetReturnValue(args, Dart_NewBoolean(Stdin::GetLineMode())); 53 bool enabled = false;
54 if (Stdin::GetLineMode(&enabled)) {
55 Dart_SetReturnValue(args, Dart_NewBoolean(enabled));
56 } else {
57 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
58 }
40 } 59 }
41 60
42 61
43 void FUNCTION_NAME(Stdin_SetLineMode)(Dart_NativeArguments args) { 62 void FUNCTION_NAME(Stdin_SetLineMode)(Dart_NativeArguments args) {
44 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); 63 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0));
45 Stdin::SetLineMode(enabled); 64 if (Stdin::SetLineMode(enabled)) {
65 Dart_SetReturnValue(args, Dart_True());
66 } else {
67 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
68 }
46 } 69 }
47 70
48 71
49 void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) { 72 void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) {
50 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { 73 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) {
51 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 74 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
52 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); 75 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
53 return; 76 return;
54 } 77 }
55 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); 78 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0));
(...skipping 10 matching lines...) Expand all
66 Dart_SetReturnValue(args, list); 89 Dart_SetReturnValue(args, list);
67 } else { 90 } else {
68 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 91 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
69 } 92 }
70 } 93 }
71 94
72 } // namespace bin 95 } // namespace bin
73 } // namespace dart 96 } // namespace dart
74 97
75 #endif // !defined(DART_IO_DISABLED) 98 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/stdio.h ('k') | runtime/bin/stdio_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698