From: Rob Landley Date: Mon, 15 Jan 2018 05:15:01 +0000 (-0600) Subject: Switch xgettty() -> tty_fd() (returning -1 instead of erroring out if none). X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fexternal-toybox.git;a=commitdiff_plain;h=4577605121fa441e5a28c32ce2c33be4c48df89b Switch xgettty() -> tty_fd() (returning -1 instead of erroring out if none). --- diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c index f028f5e9..073a67dd 100644 --- a/lib/interestingtimes.c +++ b/lib/interestingtimes.c @@ -5,13 +5,13 @@ #include "toys.h" -int xgettty(void) +int tty_fd(void) { int i, j; for (i = 0; i<3; i++) if (isatty(j = (i+1)%3)) return j; - return xopen("/dev/tty", O_RDWR); + return notstdio(open("/dev/tty", O_RDWR)); } // Quick and dirty query size of terminal, doesn't do ANSI probe fallback. diff --git a/lib/lib.h b/lib/lib.h index 5dd629d2..94662983 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -274,7 +274,7 @@ int draw_trim_esc(char *str, int padto, int width, char *escmore, int draw_trim(char *str, int padto, int width); // interestingtimes.c -int xgettty(void); +int tty_fd(void); int terminal_size(unsigned *xx, unsigned *yy); int terminal_probesize(unsigned *xx, unsigned *yy); int scan_key_getsize(char *scratch, int miliwait, unsigned *xx, unsigned *yy); diff --git a/toys/other/reset.c b/toys/other/reset.c index 0c2089cc..aa9b74ea 100644 --- a/toys/other/reset.c +++ b/toys/other/reset.c @@ -18,6 +18,8 @@ config RESET void reset_main(void) { - // man 4 console codes: reset terminal is ESC (no left bracket) c - xwrite(xgettty(), "\033c", 2); + int fd = tty_fd(); + + // man 4 console_codes: reset terminal is ESC (no left bracket) c + xwrite(fd<0 ? 1 : fd, "\033c", 2); }