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

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

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « runtime/bin/stdio_linux.cc ('k') | runtime/bin/stdio_win.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 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/stdio.h"
9
8 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
9 #include <sys/ioctl.h> // NOLINT 11 #include <sys/ioctl.h> // NOLINT
10 #include <termios.h> // NOLINT 12 #include <termios.h> // NOLINT
11 13
12 #include "bin/stdio.h"
13 #include "bin/fdutils.h" 14 #include "bin/fdutils.h"
14
15 #include "platform/signal_blocker.h" 15 #include "platform/signal_blocker.h"
16 16
17
18 namespace dart { 17 namespace dart {
19 namespace bin { 18 namespace bin {
20 19
21 int Stdin::ReadByte() { 20 int Stdin::ReadByte() {
22 int c = getchar(); 21 int c = getchar();
23 if (c == EOF) { 22 if (c == EOF) {
24 c = -1; 23 c = -1;
25 } 24 }
26 return c; 25 return c;
27 } 26 }
28 27
29 28
30 bool Stdin::GetEchoMode() { 29 bool Stdin::GetEchoMode() {
31 struct termios term; 30 struct termios term;
32 tcgetattr(STDIN_FILENO, &term); 31 tcgetattr(STDIN_FILENO, &term);
33 return (term.c_lflag & ECHO) != 0; 32 return ((term.c_lflag & ECHO) != 0);
34 } 33 }
35 34
36 35
37 void Stdin::SetEchoMode(bool enabled) { 36 void Stdin::SetEchoMode(bool enabled) {
38 struct termios term; 37 struct termios term;
39 tcgetattr(STDIN_FILENO, &term); 38 tcgetattr(STDIN_FILENO, &term);
40 if (enabled) { 39 if (enabled) {
41 term.c_lflag |= ECHO|ECHONL; 40 term.c_lflag |= (ECHO | ECHONL);
42 } else { 41 } else {
43 term.c_lflag &= ~(ECHO|ECHONL); 42 term.c_lflag &= ~(ECHO | ECHONL);
44 } 43 }
45 tcsetattr(STDIN_FILENO, TCSANOW, &term); 44 tcsetattr(STDIN_FILENO, TCSANOW, &term);
46 } 45 }
47 46
48 47
49 bool Stdin::GetLineMode() { 48 bool Stdin::GetLineMode() {
50 struct termios term; 49 struct termios term;
51 tcgetattr(STDIN_FILENO, &term); 50 tcgetattr(STDIN_FILENO, &term);
52 return (term.c_lflag & ICANON) != 0; 51 return ((term.c_lflag & ICANON) != 0);
53 } 52 }
54 53
55 54
56 void Stdin::SetLineMode(bool enabled) { 55 void Stdin::SetLineMode(bool enabled) {
57 struct termios term; 56 struct termios term;
58 tcgetattr(STDIN_FILENO, &term); 57 tcgetattr(STDIN_FILENO, &term);
59 if (enabled) { 58 if (enabled) {
60 term.c_lflag |= ICANON; 59 term.c_lflag |= ICANON;
61 } else { 60 } else {
62 term.c_lflag &= ~(ICANON); 61 term.c_lflag &= ~(ICANON);
63 } 62 }
64 tcsetattr(STDIN_FILENO, TCSANOW, &term); 63 tcsetattr(STDIN_FILENO, TCSANOW, &term);
65 } 64 }
66 65
67 66
68 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { 67 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
69 struct winsize w; 68 struct winsize w;
70 if (NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w) == 0) && 69 int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w));
71 (w.ws_col != 0 || w.ws_row != 0)) { 70 if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) {
72 size[0] = w.ws_col; 71 size[0] = w.ws_col;
73 size[1] = w.ws_row; 72 size[1] = w.ws_row;
74 return true; 73 return true;
75 } 74 }
76 return false; 75 return false;
77 } 76 }
78 77
79 } // namespace bin 78 } // namespace bin
80 } // namespace dart 79 } // namespace dart
81 80
82 #endif // defined(TARGET_OS_MACOS) 81 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/stdio_linux.cc ('k') | runtime/bin/stdio_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698