aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-03-19 19:19:21 -0500
committerRob Landley <rob@landley.net>2012-03-19 19:19:21 -0500
commitee00a7f4587c1b75dedb71b5aa3d12608fb7b54c (patch)
tree1898173cb11a34f3565ea134286e1060f8b0e743 /lib/lib.c
parent522d90613ae7dc728a98d3ce3b939b4ad9b30f25 (diff)
downloadtoybox-ee00a7f4587c1b75dedb71b5aa3d12608fb7b54c.tar.gz
Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
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;
}