Mercurial > hg > toybox
diff lib/lib.c @ 550:b2194045c40e
Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 19 Mar 2012 19:19:21 -0500 |
parents | d51be130fda2 |
children | 2548e6e590b2 |
line wrap: on
line diff
--- a/lib/lib.c Fri Mar 16 06:42:08 2012 -0500 +++ b/lib/lib.c Mon Mar 19 19:19:21 2012 -0500 @@ -794,18 +794,21 @@ // 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; - 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; + 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; + + break; } + fclose(fp); + return def; }