diff options
author | Rob Landley <rob@landley.net> | 2012-03-19 19:19:21 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-03-19 19:19:21 -0500 |
commit | ee00a7f4587c1b75dedb71b5aa3d12608fb7b54c (patch) | |
tree | 1898173cb11a34f3565ea134286e1060f8b0e743 /lib/lib.c | |
parent | 522d90613ae7dc728a98d3ce3b939b4ad9b30f25 (diff) | |
download | toybox-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.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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; } |