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

Unified Diff: runtime/bin/stdio_win.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/stdio_patch.dart ('k') | sdk/lib/io/stdio.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/stdio_win.cc
diff --git a/runtime/bin/stdio_win.cc b/runtime/bin/stdio_win.cc
index d06282643452c870ebd4eac03114708b3a382d62..5c797847cd30283c4d306f0fbf8c4ddae6c6b9f2 100644
--- a/runtime/bin/stdio_win.cc
+++ b/runtime/bin/stdio_win.cc
@@ -12,65 +12,68 @@
namespace dart {
namespace bin {
-int Stdin::ReadByte() {
+bool Stdin::ReadByte(int* byte) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
uint8_t buffer[1];
DWORD read = 0;
- int c = -1;
- if (ReadFile(h, buffer, 1, &read, NULL) && (read == 1)) {
- c = buffer[0];
+ BOOL success = ReadFile(h, buffer, 1, &read, NULL);
+ if (!success && (GetLastError() != ERROR_BROKEN_PIPE)) {
+ return false;
}
- return c;
+ *byte = (read == 1) ? buffer[0] : -1;
+ return true;
}
-bool Stdin::GetEchoMode() {
+bool Stdin::GetEchoMode(bool* enabled) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
if (!GetConsoleMode(h, &mode)) {
return false;
}
- return ((mode & ENABLE_ECHO_INPUT) != 0);
+ *enabled = ((mode & ENABLE_ECHO_INPUT) != 0);
+ return true;
}
-void Stdin::SetEchoMode(bool enabled) {
+bool Stdin::SetEchoMode(bool enabled) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
if (!GetConsoleMode(h, &mode)) {
- return;
+ return false;
}
if (enabled) {
mode |= ENABLE_ECHO_INPUT;
} else {
mode &= ~ENABLE_ECHO_INPUT;
}
- SetConsoleMode(h, mode);
+ return SetConsoleMode(h, mode);
}
-bool Stdin::GetLineMode() {
+bool Stdin::GetLineMode(bool* enabled) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
if (!GetConsoleMode(h, &mode)) {
return false;
}
- return (mode & ENABLE_LINE_INPUT) != 0;
+ *enabled = (mode & ENABLE_LINE_INPUT) != 0;
+ return true;
}
-void Stdin::SetLineMode(bool enabled) {
+bool Stdin::SetLineMode(bool enabled) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
if (!GetConsoleMode(h, &mode)) {
- return;
+ return false;
}
if (enabled) {
mode |= ENABLE_LINE_INPUT;
} else {
mode &= ~ENABLE_LINE_INPUT;
}
- SetConsoleMode(h, mode);
+ return SetConsoleMode(h, mode);
}
« no previous file with comments | « runtime/bin/stdio_patch.dart ('k') | sdk/lib/io/stdio.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698