aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-11 16:44:15 -0600
committerRob Landley <rob@landley.net>2018-12-11 16:44:15 -0600
commitd4017dbd0a422953bc439db467db9c36d5dd4e33 (patch)
tree95040470f9cc93e7c82279821ae315ac509a09aa /toys/posix
parent06af852a0f369a5a0f608ee4cbaef487c8493f3e (diff)
downloadtoybox-d4017dbd0a422953bc439db467db9c36d5dd4e33.tar.gz
Implement --preserve default = mot behavior (fixes segfault when no argument).
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/cp.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/toys/posix/cp.c b/toys/posix/cp.c
index 0b1d0e49..da658319 100644
--- a/toys/posix/cp.c
+++ b/toys/posix/cp.c
@@ -369,13 +369,12 @@ void cp_main(void)
if ((toys.optc>1 || (toys.optflags&FLAG_D)) && !destdir)
error_exit("'%s' not directory", destname);
- if (toys.optflags & (FLAG_a|FLAG_p)) {
+ if (toys.optflags & (FLAG_a|FLAG_p))
TT.pflags = _CP_mode|_CP_ownership|_CP_timestamps;
- umask(0);
- }
+
// Not using comma_args() (yet?) because interpeting as letters.
if (CFG_CP_PRESERVE && (toys.optflags & FLAG_preserve)) {
- char *pre = xstrdup(TT.c.preserve), *s;
+ char *pre = xstrdup(TT.c.preserve ? TT.c.preserve : "mot"), *s;
if (comma_scan(pre, "all", 1)) TT.pflags = ~0;
for (i=0; i<ARRAY_LEN(cp_preserve); i++)
@@ -383,7 +382,7 @@ void cp_main(void)
if (*pre) {
// Try to interpret as letters, commas won't set anything this doesn't.
- for (s = TT.c.preserve; *s; s++) {
+ for (s = pre; *s; s++) {
for (i=0; i<ARRAY_LEN(cp_preserve); i++)
if (*s == *cp_preserve[i].name) break;
if (i == ARRAY_LEN(cp_preserve)) {
@@ -396,6 +395,7 @@ void cp_main(void)
}
free(pre);
}
+ if (TT.pflags & _CP_mode) umask(0);
if (!TT.callback) TT.callback = cp_node;
// Loop through sources