aboutsummaryrefslogtreecommitdiff
path: root/toys
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 /toys
parentb0dcd667f185e01589af38958116768ffd561de8 (diff)
downloadtoybox-f793d5347f08bdb742e8ad8a2cc5a7d30e6bd623.tar.gz
Upgrade yesno() and make cp -i use it.
Diffstat (limited to 'toys')
-rw-r--r--toys/cp.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/toys/cp.c b/toys/cp.c
index e9d9d503..236c00f7 100644
--- a/toys/cp.c
+++ b/toys/cp.c
@@ -58,18 +58,11 @@ DEFINE_GLOBALS(
void cp_file(char *src, char *dst, struct stat *srcst)
{
int fdout = -1;
- char overwrite;
-
- if ((toys.optflags & FLAG_i) && access(dst, R_OK) == 0) {
- // -i flag is specified and dst file exists.
- // If user does not confirm, don't copy the file
- // Ideally I'd use perror here, but it always appends a newline
- // to the string, resulting in the input prompt being displayed
- // on the next line.
- fprintf(stderr, "cp: overwrite '%s'? ", dst);
- (void)scanf("%c", &overwrite);
- if (!(overwrite == 'y' || overwrite == 'Y')) return;
- }
+
+ // -i flag is specified and dst file exists.
+ if ((toys.optflags&FLAG_i) && !access(dst, R_OK)
+ && !yesno("cp: overwrite", 1))
+ return;
if (toys.optflags & FLAG_v)
printf("'%s' -> '%s'\n", src, dst);