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

Unified Diff: runtime/bin/stdio_macos.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_linux.cc ('k') | runtime/bin/stdio_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/stdio_macos.cc
diff --git a/runtime/bin/stdio_macos.cc b/runtime/bin/stdio_macos.cc
index a8bd15973d793bfd131ca6c81dc1f6dea5076e1a..9481395a775f9e3722ce37cd0f1b3afc12e67fa8 100644
--- a/runtime/bin/stdio_macos.cc
+++ b/runtime/bin/stdio_macos.cc
@@ -19,50 +19,67 @@
namespace dart {
namespace bin {
-int Stdin::ReadByte() {
- int c = getchar();
- if (c == EOF) {
- c = -1;
+bool Stdin::ReadByte(int* byte) {
+ int c = NO_RETRY_EXPECTED(getchar());
+ if ((c == EOF) && (errno != 0)) {
+ return false;
}
- return c;
+ *byte = (c == EOF) ? -1 : c;
+ return true;
}
-bool Stdin::GetEchoMode() {
+bool Stdin::GetEchoMode(bool* enabled) {
struct termios term;
- tcgetattr(STDIN_FILENO, &term);
- return ((term.c_lflag & ECHO) != 0);
+ int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
+ if (status != 0) {
+ return false;
+ }
+ *enabled = ((term.c_lflag & ECHO) != 0);
+ return true;
}
-void Stdin::SetEchoMode(bool enabled) {
+bool Stdin::SetEchoMode(bool enabled) {
struct termios term;
- tcgetattr(STDIN_FILENO, &term);
+ int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
+ if (status != 0) {
+ return false;
+ }
if (enabled) {
term.c_lflag |= (ECHO | ECHONL);
} else {
term.c_lflag &= ~(ECHO | ECHONL);
}
- tcsetattr(STDIN_FILENO, TCSANOW, &term);
+ status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term));
+ return (status == 0);
}
-bool Stdin::GetLineMode() {
+bool Stdin::GetLineMode(bool* enabled) {
struct termios term;
- tcgetattr(STDIN_FILENO, &term);
- return ((term.c_lflag & ICANON) != 0);
+ int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
+ if (status != 0) {
+ return false;
+ }
+ *enabled = ((term.c_lflag & ICANON) != 0);
+ return true;
}
-void Stdin::SetLineMode(bool enabled) {
+bool Stdin::SetLineMode(bool enabled) {
struct termios term;
- tcgetattr(STDIN_FILENO, &term);
+ int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
+ if (status != 0) {
+ return false;
+ }
if (enabled) {
term.c_lflag |= ICANON;
} else {
term.c_lflag &= ~(ICANON);
}
- tcsetattr(STDIN_FILENO, TCSANOW, &term);
+ status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term));
+ return (status == 0);
}
« no previous file with comments | « runtime/bin/stdio_linux.cc ('k') | runtime/bin/stdio_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698