diff options
author | Rob Landley <rob@landley.net> | 2012-12-08 02:25:32 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-12-08 02:25:32 -0600 |
commit | db8eb323b3b8ded0eb75c0872563784ae4356e99 (patch) | |
tree | 429e99b874b2510723d94bf6e736a51fd2a44ba5 /lib | |
parent | c087a4a911c29f081efbdbaf7c4513f34acf1928 (diff) | |
download | toybox-db8eb323b3b8ded0eb75c0872563784ae4356e99.tar.gz |
Make yesno() always read from stdin and write to stderr. (If we need to find our tty, open /dev/tty, but existing users don't.)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 19 |
1 files changed, 6 insertions, 13 deletions
@@ -958,24 +958,17 @@ void terminal_size(unsigned *x, unsigned *y) } } -// This should use a raw tty, fixit later. int yesno(char *prompt, int def) { - FILE *fps[] = {stdin, stdout, stderr}; - int i; char buf; - for (i=0; i<3; i++) if (isatty(i)) break; - if (i == 3) return 1; - - fprintf(fps[i], "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N'); - fflush(fps[i]); - while (fread(&buf, 1, 1, fps[i])) { - if (tolower(buf) == 'y') def = 1; - if (tolower(buf) == 'n') def = 0; - else if (!isspace(buf)) continue; + fprintf(stderr, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N'); + fflush(stderr); + while (fread(&buf, 1, 1, stdin)) { + int new; - break; + if (isspace(buf)) break; + if (-1 != (new = stridx("ny", tolower(buf)))) def = new; } return def; |