# HG changeset patch # User Rob Landley # Date 1332259854 18000 # Node ID 997e016fbdf0e3661b2e33d6c3381818fcdfc3ac # Parent 75da5d793fc81a8290ce7f52feeb11b963298314 Using /dev/tty for yesno() is wrong because yes 'n' | cp -ial needs to work. diff -r 75da5d793fc8 -r 997e016fbdf0 lib/lib.c --- a/lib/lib.c Mon Mar 19 20:56:18 2012 -0500 +++ b/lib/lib.c Tue Mar 20 11:10:54 2012 -0500 @@ -794,20 +794,22 @@ // This should use a raw tty, fixit later. int yesno(char *prompt, int def) { - FILE *fp = fopen("/dev/tty", "rw"); + FILE *fps[] = {stdin, stdout, stderr}; + int i; char buf; - if (!fp) return 1; + for (i=0; i<3; i++) if (isatty(i)) break; + if (i == 3) return 1; - fprintf(fp, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N'); - while (fread(&buf, 1, 1, fp)) { + 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; break; } - fclose(fp); return def; }