aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-12-08 02:25:32 -0600
committerRob Landley <rob@landley.net>2012-12-08 02:25:32 -0600
commitdb8eb323b3b8ded0eb75c0872563784ae4356e99 (patch)
tree429e99b874b2510723d94bf6e736a51fd2a44ba5 /lib
parentc087a4a911c29f081efbdbaf7c4513f34acf1928 (diff)
downloadtoybox-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.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 36f78ceb..f452bf3c 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -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;