Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Mini cp implementation for busybox |
| 4 | * |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 5 | * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu> |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 6 | * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp> |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 9 | */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 10 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
| 11 | * |
| 12 | * Size reduction. |
| 13 | */ |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 14 | //config:config CP |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 15 | //config: bool "cp (10 kb)" |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 16 | //config: default y |
| 17 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 18 | //config: cp is used to copy files and directories. |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 19 | //config: |
| 20 | //config:config FEATURE_CP_LONG_OPTIONS |
Denys Vlasenko | f560422 | 2017-01-10 14:58:54 +0100 | [diff] [blame] | 21 | //config: bool "Enable long options" |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 22 | //config: default y |
| 23 | //config: depends on CP && LONG_OPTS |
| 24 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 25 | //config: Enable long options. |
| 26 | //config: Also add support for --parents option. |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 27 | //config: |
| 28 | //config:config FEATURE_CP_REFLINK |
Denys Vlasenko | 1fbb73f | 2018-07-17 00:16:16 +0200 | [diff] [blame] | 29 | //config: bool "Enable --reflink[=auto]" |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 30 | //config: default y |
| 31 | //config: depends on FEATURE_CP_LONG_OPTIONS |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 32 | |
| 33 | //applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) |
Denys Vlasenko | 88663e4 | 2018-01-14 14:41:52 +0100 | [diff] [blame] | 34 | /* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */ |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 35 | |
| 36 | //kbuild:lib-$(CONFIG_CP) += cp.o |
| 37 | |
| 38 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 39 | |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 40 | // Options of cp from GNU coreutils 6.10: |
| 41 | // -a, --archive |
| 42 | // -f, --force |
| 43 | // -i, --interactive |
| 44 | // -l, --link |
| 45 | // -L, --dereference |
| 46 | // -P, --no-dereference |
| 47 | // -R, -r, --recursive |
| 48 | // -s, --symbolic-link |
| 49 | // -v, --verbose |
| 50 | // -H follow command-line symbolic links in SOURCE |
| 51 | // -d same as --no-dereference --preserve=links |
| 52 | // -p same as --preserve=mode,ownership,timestamps |
| 53 | // -c same as --preserve=context |
| 54 | // -u, --update |
| 55 | // copy only when the SOURCE file is newer than the destination |
| 56 | // file or when the destination file is missing |
| 57 | // --remove-destination |
| 58 | // remove each existing destination file before attempting to open |
| 59 | // --parents |
| 60 | // use full source file name under DIRECTORY |
| 61 | // -T, --no-target-directory |
| 62 | // treat DEST as a normal file |
| 63 | // NOT SUPPORTED IN BBOX: |
| 64 | // --backup[=CONTROL] |
| 65 | // make a backup of each existing destination file |
| 66 | // -b like --backup but does not accept an argument |
| 67 | // --copy-contents |
| 68 | // copy contents of special files when recursive |
| 69 | // --preserve[=ATTR_LIST] |
| 70 | // preserve attributes (default: mode,ownership,timestamps), |
| 71 | // if possible additional attributes: security context,links,all |
| 72 | // --no-preserve=ATTR_LIST |
| 73 | // --sparse=WHEN |
| 74 | // control creation of sparse files |
| 75 | // --strip-trailing-slashes |
| 76 | // remove any trailing slashes from each SOURCE argument |
| 77 | // -S, --suffix=SUFFIX |
| 78 | // override the usual backup suffix |
| 79 | // -t, --target-directory=DIRECTORY |
| 80 | // copy all SOURCE arguments into DIRECTORY |
| 81 | // -x, --one-file-system |
| 82 | // stay on this file system |
| 83 | // -Z, --context=CONTEXT |
| 84 | // (SELinux) set SELinux security context of copy to CONTEXT |
| 85 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 86 | //usage:#define cp_trivial_usage |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 87 | //usage: "[-arPLHpfinlsTu] SOURCE DEST\n" |
| 88 | //usage: "or: cp [-arPLHpfinlsu] SOURCE... { -t DIRECTORY | DIRECTORY }" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 89 | //usage:#define cp_full_usage "\n\n" |
Denys Vlasenko | ba9f9c2 | 2021-04-14 15:15:45 +0200 | [diff] [blame] | 90 | //usage: "Copy SOURCEs to DEST\n" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 91 | //usage: "\n -a Same as -dpR" |
| 92 | //usage: IF_SELINUX( |
| 93 | //usage: "\n -c Preserve security context" |
| 94 | //usage: ) |
| 95 | //usage: "\n -R,-r Recurse" |
| 96 | //usage: "\n -d,-P Preserve symlinks (default if -R)" |
| 97 | //usage: "\n -L Follow all symlinks" |
| 98 | //usage: "\n -H Follow symlinks on command line" |
| 99 | //usage: "\n -p Preserve file attributes if possible" |
| 100 | //usage: "\n -f Overwrite" |
| 101 | //usage: "\n -i Prompt before overwrite" |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 102 | //usage: "\n -n Don't overwrite" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 103 | //usage: "\n -l,-s Create (sym)links" |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 104 | //usage: "\n -T Refuse to copy if DEST is a directory" |
| 105 | //usage: "\n -t DIR Copy all SOURCEs into DIR" |
Denys Vlasenko | 877dedb | 2016-05-27 00:46:38 +0200 | [diff] [blame] | 106 | //usage: "\n -u Copy only newer files" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 107 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 108 | #include "libbb.h" |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 109 | #include "libcoreutils/coreutils.h" |
| 110 | |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 111 | /* This is a NOEXEC applet. Be very careful! */ |
| 112 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 113 | int cp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 114 | int cp_main(int argc, char **argv) |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 115 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 116 | struct stat source_stat; |
| 117 | struct stat dest_stat; |
| 118 | const char *last; |
| 119 | const char *dest; |
| 120 | int s_flags; |
| 121 | int d_flags; |
| 122 | int flags; |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 123 | int status; |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 124 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
Ron Yorston | 98cb561 | 2021-08-10 09:13:02 +0100 | [diff] [blame] | 125 | enum { |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 126 | /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTBITS */ |
| 127 | OPT_parents = 1 << (FILEUTILS_CP_OPTBITS+1), |
| 128 | OPT_reflink = 1 << (FILEUTILS_CP_OPTBITS+2), |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 129 | }; |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 130 | # if ENABLE_FEATURE_CP_REFLINK |
| 131 | char *reflink = NULL; |
| 132 | # endif |
Denys Vlasenko | 22542ec | 2017-08-08 21:55:02 +0200 | [diff] [blame] | 133 | flags = getopt32long(argv, "^" |
| 134 | FILEUTILS_CP_OPTSTR |
| 135 | "\0" |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 136 | // Need at least one argument. (Usually two+, but -t DIR can have only one) |
Denys Vlasenko | 22542ec | 2017-08-08 21:55:02 +0200 | [diff] [blame] | 137 | // Soft- and hardlinking doesn't mix |
| 138 | // -P and -d are the same (-P is POSIX, -d is GNU) |
| 139 | // -r and -R are the same |
| 140 | // -R (and therefore -r) turns on -d (coreutils does this) |
| 141 | // -a = -pdR |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 142 | // -i overrides -n and vice versa (last wins) |
| 143 | "-1:l--s:s--l:Pd:rRd:Rd:apdR:i-n:n-i", |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 144 | "archive\0" No_argument "a" |
| 145 | "force\0" No_argument "f" |
| 146 | "interactive\0" No_argument "i" |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 147 | "no-clobber\0" No_argument "n" |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 148 | "link\0" No_argument "l" |
| 149 | "dereference\0" No_argument "L" |
| 150 | "no-dereference\0" No_argument "P" |
| 151 | "recursive\0" No_argument "R" |
| 152 | "symbolic-link\0" No_argument "s" |
Aaro Koskinen | d15d7a0 | 2018-02-01 09:29:05 +0100 | [diff] [blame] | 153 | "no-target-directory\0" No_argument "T" |
Denys Vlasenko | 56bbbfa | 2021-06-22 15:28:34 +0200 | [diff] [blame] | 154 | "target-directory\0" Required_argument "t" |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 155 | "verbose\0" No_argument "v" |
Denys Vlasenko | 877dedb | 2016-05-27 00:46:38 +0200 | [diff] [blame] | 156 | "update\0" No_argument "u" |
| 157 | "remove-destination\0" No_argument "\xff" |
| 158 | "parents\0" No_argument "\xfe" |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 159 | # if ENABLE_FEATURE_CP_REFLINK |
| 160 | "reflink\0" Optional_argument "\xfd" |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 161 | # endif |
| 162 | , &last |
| 163 | # if ENABLE_FEATURE_CP_REFLINK |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 164 | , &reflink |
| 165 | # endif |
Denys Vlasenko | 036585a | 2017-08-08 16:38:18 +0200 | [diff] [blame] | 166 | ); |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 167 | # if ENABLE_FEATURE_CP_REFLINK |
Denys Vlasenko | d01c9aa | 2018-08-01 18:29:41 +0200 | [diff] [blame] | 168 | BUILD_BUG_ON((int)OPT_reflink != (int)FILEUTILS_REFLINK); |
Denys Vlasenko | 79fb6ac | 2018-07-13 20:30:02 +0200 | [diff] [blame] | 169 | if (flags & FILEUTILS_REFLINK) { |
| 170 | if (!reflink) |
| 171 | flags |= FILEUTILS_REFLINK_ALWAYS; |
| 172 | else if (strcmp(reflink, "always") == 0) |
| 173 | flags |= FILEUTILS_REFLINK_ALWAYS; |
| 174 | else if (strcmp(reflink, "auto") != 0) |
| 175 | bb_show_usage(); |
| 176 | } |
| 177 | # endif |
Denys Vlasenko | 036585a | 2017-08-08 16:38:18 +0200 | [diff] [blame] | 178 | #else |
Denys Vlasenko | 7f44140 | 2018-02-11 21:25:23 +0100 | [diff] [blame] | 179 | flags = getopt32(argv, "^" |
| 180 | FILEUTILS_CP_OPTSTR |
| 181 | "\0" |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 182 | "-1:l--s:s--l:Pd:rRd:Rd:apdR" |
| 183 | , &last |
Denys Vlasenko | 7f44140 | 2018-02-11 21:25:23 +0100 | [diff] [blame] | 184 | ); |
Denys Vlasenko | 036585a | 2017-08-08 16:38:18 +0200 | [diff] [blame] | 185 | #endif |
Denis Vlasenko | 6666ac4 | 2007-08-24 21:46:24 +0000 | [diff] [blame] | 186 | argc -= optind; |
| 187 | argv += optind; |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 188 | /* Reverse this bit. If there is -d, bit is not set: */ |
| 189 | flags ^= FILEUTILS_DEREFERENCE; |
Denis Vlasenko | c0431ed | 2008-04-27 22:06:24 +0000 | [diff] [blame] | 190 | /* coreutils 6.9 compat: |
| 191 | * by default, "cp" derefs symlinks (creates regular dest files), |
| 192 | * but "cp -R" does not. We switch off deref if -r or -R (see above). |
| 193 | * However, "cp -RL" must still deref symlinks: */ |
| 194 | if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */ |
| 195 | flags |= FILEUTILS_DEREFERENCE; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 196 | |
Denis Vlasenko | c86e052 | 2007-03-20 11:30:28 +0000 | [diff] [blame] | 197 | #if ENABLE_SELINUX |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 198 | if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) { |
| 199 | selinux_or_die(); |
| 200 | } |
| 201 | #endif |
| 202 | |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 203 | status = EXIT_SUCCESS; |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 204 | if (!(flags & FILEUTILS_TARGET_DIR)) { |
| 205 | last = argv[argc - 1]; |
| 206 | if (argc < 2) |
| 207 | bb_show_usage(); |
| 208 | if (argc != 2) { |
| 209 | if (flags & FILEUTILS_NO_TARGET_DIR) |
| 210 | bb_show_usage(); |
| 211 | /* "cp A B C... DIR" - target must be dir */ |
| 212 | } else /* argc == 2 */ { |
| 213 | /* "cp A B" - only case where target can be not a dir */ |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 214 | s_flags = cp_mv_stat2(*argv, &source_stat, |
| 215 | (flags & FILEUTILS_DEREFERENCE) ? stat : lstat); |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 216 | if (s_flags < 0) /* error other than ENOENT */ |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 217 | return EXIT_FAILURE; |
| 218 | d_flags = cp_mv_stat(last, &dest_stat); |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 219 | if (d_flags < 0) /* error other than ENOENT */ |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 220 | return EXIT_FAILURE; |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 221 | |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 222 | if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */ |
| 223 | if (!(s_flags & 2) && (d_flags & 2)) |
| 224 | /* cp -T NOTDIR DIR */ |
| 225 | bb_error_msg_and_die("'%s' is a directory", last); |
| 226 | } |
Aaro Koskinen | d15d7a0 | 2018-02-01 09:29:05 +0100 | [diff] [blame] | 227 | |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 228 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 229 | //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", |
| 230 | // flags, FILEUTILS_RMDEST, OPT_parents); |
| 231 | if (flags & OPT_parents) { |
| 232 | if (!(d_flags & 2)) { |
| 233 | bb_simple_error_msg_and_die("with --parents, the destination must be a directory"); |
| 234 | } |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 235 | } |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 236 | if (flags & FILEUTILS_RMDEST) { |
| 237 | flags |= FILEUTILS_FORCE; |
| 238 | } |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 239 | #endif |
| 240 | |
Denys Vlasenko | 1de709f | 2021-06-21 19:31:37 +0200 | [diff] [blame] | 241 | /* ...if neither is a directory... */ |
| 242 | if (!((s_flags | d_flags) & 2) |
| 243 | /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ |
| 244 | || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) |
| 245 | || (flags & FILEUTILS_NO_TARGET_DIR) |
| 246 | ) { |
| 247 | /* Do a simple copy */ |
| 248 | dest = last; |
| 249 | goto DO_COPY; /* NB: argc==2 -> *++argv==last */ |
| 250 | } |
Denys Vlasenko | 0ec52d4 | 2021-06-21 19:35:33 +0200 | [diff] [blame] | 251 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 252 | } |
Ron Yorston | a84bbc5 | 2021-06-24 15:08:15 +0100 | [diff] [blame] | 253 | /* else: last is DIR from "-t DIR" */ |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 254 | |
Denis Vlasenko | 6666ac4 | 2007-08-24 21:46:24 +0000 | [diff] [blame] | 255 | while (1) { |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 256 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
| 257 | if (flags & OPT_parents) { |
| 258 | char *dest_dup; |
| 259 | char *dest_dir; |
| 260 | dest = concat_path_file(last, *argv); |
| 261 | dest_dup = xstrdup(dest); |
| 262 | dest_dir = dirname(dest_dup); |
| 263 | if (bb_make_directory(dest_dir, -1, FILEUTILS_RECUR)) { |
| 264 | return EXIT_FAILURE; |
| 265 | } |
| 266 | free(dest_dup); |
| 267 | goto DO_COPY; |
| 268 | } |
| 269 | #endif |
Denis Vlasenko | 818322b | 2007-09-24 18:27:04 +0000 | [diff] [blame] | 270 | dest = concat_path_file(last, bb_get_last_path_component_strip(*argv)); |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 271 | DO_COPY: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 272 | if (copy_file(*argv, dest, flags) < 0) { |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 273 | status = EXIT_FAILURE; |
Denis Vlasenko | 6666ac4 | 2007-08-24 21:46:24 +0000 | [diff] [blame] | 274 | } |
Ron Yorston | a84bbc5 | 2021-06-24 15:08:15 +0100 | [diff] [blame] | 275 | if (!*++argv || *argv == last) { |
Denys Vlasenko | d5fddcd | 2009-10-08 01:32:44 +0200 | [diff] [blame] | 276 | /* possibly leaking dest... */ |
Denys Vlasenko | 48f1161 | 2009-09-26 14:31:04 +0200 | [diff] [blame] | 277 | break; |
| 278 | } |
Denys Vlasenko | d5fddcd | 2009-10-08 01:32:44 +0200 | [diff] [blame] | 279 | /* don't move up: dest may be == last and not malloced! */ |
| 280 | free((void*)dest); |
Denis Vlasenko | 6666ac4 | 2007-08-24 21:46:24 +0000 | [diff] [blame] | 281 | } |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 282 | |
Denis Vlasenko | 6666ac4 | 2007-08-24 21:46:24 +0000 | [diff] [blame] | 283 | /* Exit. We are NOEXEC, not NOFORK. We do exit at the end of main() */ |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 284 | return status; |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 285 | } |