aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/lib.c b/lib/lib.c
index a1f4a528..6a2e7d98 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -794,18 +794,21 @@ void terminal_size(unsigned *x, unsigned *y)
// This should use a raw tty, fixit later.
int yesno(char *prompt, int def)
{
+ FILE *fp = fopen("/dev/tty", "rw");
char buf;
- int i;
- for (i=0; i<3 && !isatty(i); i++);
- if (i == 3) return 1;
+ if (!fp) return 1;
+
+ fprintf(fp, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N');
+ while (fread(&buf, 1, 1, fp)) {
+ if (tolower(buf) == 'y') def = 1;
+ if (tolower(buf) == 'n') def = 0;
+ else if (!isspace(buf)) continue;
- fdprintf(i, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N');
- while (read(i, &buf, 1)) {
- if (isspace(buf)) break;
- if (tolower(buf) == 'y') return 1;
- if (tolower(buf) == 'n') return 0;
+ break;
}
+ fclose(fp);
+
return def;
}