* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
* SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
*
- * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
* Size reduction.
*/
+//usage:#define cp_trivial_usage
+//usage: "[OPTIONS] SOURCE... DEST"
+//usage:#define cp_full_usage "\n\n"
+//usage: "Copy SOURCE(s) to DEST\n"
+//usage: "\n -a Same as -dpR"
+//usage: IF_SELINUX(
+//usage: "\n -c Preserve security context"
+//usage: )
+//usage: "\n -R,-r Recurse"
+//usage: "\n -d,-P Preserve symlinks (default if -R)"
+//usage: "\n -L Follow all symlinks"
+//usage: "\n -H Follow symlinks on command line"
+//usage: "\n -p Preserve file attributes if possible"
+//usage: "\n -f Overwrite"
+//usage: "\n -i Prompt before overwrite"
+//usage: "\n -l,-s Create (sym)links"
+
#include "libbb.h"
#include "libcoreutils/coreutils.h"
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
- OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
- OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
+ OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
#if ENABLE_FEATURE_CP_LONG_OPTIONS
- OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
+ OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
#endif
};
// -r and -R are the same
// -R (and therefore -r) turns on -d (coreutils does this)
// -a = -pdR
- opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL";
+ opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
#if ENABLE_FEATURE_CP_LONG_OPTIONS
applet_long_options =
"archive\0" No_argument "a"
;
#endif
// -v (--verbose) is ignored
- flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHv");
+ flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
* -f, --force
*/
argc -= optind;
argv += optind;
- flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */
+ /* Reverse this bit. If there is -d, bit is not set: */
+ flags ^= FILEUTILS_DEREFERENCE;
/* coreutils 6.9 compat:
* by default, "cp" derefs symlinks (creates regular dest files),
* but "cp -R" does not. We switch off deref if -r or -R (see above).
* However, "cp -RL" must still deref symlinks: */
if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */
flags |= FILEUTILS_DEREFERENCE;
- /* The behavior of -H is *almost* like -L, but not quite, so let's
- * just ignore it too for fun. TODO.
- if (flags & OPT_H) ... // deref command-line params only
- */
#if ENABLE_SELINUX
if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {
if (copy_file(*argv, dest, flags) < 0) {
status = EXIT_FAILURE;
}
- free((void*)dest);
if (*++argv == last) {
+ /* possibly leaking dest... */
break;
}
+ /* don't move up: dest may be == last and not malloced! */
+ free((void*)dest);
}
/* Exit. We are NOEXEC, not NOFORK. We do exit at the end of main() */