aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-02-27 21:56:49 -0600
committerRob Landley <rob@landley.net>2012-02-27 21:56:49 -0600
commitf793d5347f08bdb742e8ad8a2cc5a7d30e6bd623 (patch)
tree4af5671c3f659f6038f8c1adbb2876c316b6a3cb /lib/lib.c
parentb0dcd667f185e01589af38958116768ffd561de8 (diff)
downloadtoybox-f793d5347f08bdb742e8ad8a2cc5a7d30e6bd623.tar.gz
Upgrade yesno() and make cp -i use it.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 3f04cb61..cc441f9d 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -792,20 +792,19 @@ void terminal_size(unsigned *x, unsigned *y)
}
// This should use a raw tty, fixit later.
-int yesno(int def)
+int yesno(char *prompt, int def)
{
- char buf[16];
+ char buf;
int i;
for (i=0; i<3 && !isatty(i); i++);
if (i == 3) return 1;
- sprintf(buf, "(%c/%c):", def ? 'Y' : 'y', def ? 'n' : 'N');
- write(i, buf, 6);
- while (read(i, buf, 1)) {
- if (isspace(*buf)) break;
- if (tolower(*buf) == 'y') return 1;
- if (tolower(*buf) == 'n') return 0;
+ 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;
}
return def;
}