aboutsummaryrefslogtreecommitdiff
path: root/cp_mv.c
diff options
context:
space:
mode:
Diffstat (limited to 'cp_mv.c')
-rw-r--r--cp_mv.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/cp_mv.c b/cp_mv.c
index b15235a25..3dc637d7f 100644
--- a/cp_mv.c
+++ b/cp_mv.c
@@ -45,7 +45,6 @@
45#define is_cp 0 45#define is_cp 0
46#define is_mv 1 46#define is_mv 1
47static int dz_i; /* index into cp_mv_usage */ 47static int dz_i; /* index into cp_mv_usage */
48static const char *dz; /* dollar zero, .bss */
49static const char *cp_mv_usage[] = /* .rodata */ 48static const char *cp_mv_usage[] = /* .rodata */
50{ 49{
51 "cp [OPTION]... SOURCE DEST\n" 50 "cp [OPTION]... SOURCE DEST\n"
@@ -89,7 +88,7 @@ static void name_too_long__exit (void) __attribute__((noreturn));
89static 88static
90void name_too_long__exit (void) 89void name_too_long__exit (void)
91{ 90{
92 fprintf(stderr, name_too_long, dz); 91 fprintf(stderr, name_too_long, applet_name);
93 exit(FALSE); 92 exit(FALSE);
94} 93}
95 94
@@ -124,14 +123,14 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
124 123
125 if (srcDirFlag == TRUE) { 124 if (srcDirFlag == TRUE) {
126 if (recursiveFlag == FALSE) { 125 if (recursiveFlag == FALSE) {
127 fprintf(stderr, omitting_directory, dz, baseSrcName); 126 fprintf(stderr, omitting_directory, applet_name, baseSrcName);
128 return TRUE; 127 return TRUE;
129 } 128 }
130 srcBasename = (strstr(fileName, baseSrcName) 129 srcBasename = (strstr(fileName, baseSrcName)
131 + strlen(baseSrcName)); 130 + strlen(baseSrcName));
132 131
133 if (destLen + strlen(srcBasename) > BUFSIZ) { 132 if (destLen + strlen(srcBasename) > BUFSIZ) {
134 fprintf(stderr, name_too_long, dz); 133 fprintf(stderr, name_too_long, applet_name);
135 return FALSE; 134 return FALSE;
136 } 135 }
137 strcat(destName, srcBasename); 136 strcat(destName, srcBasename);
@@ -146,7 +145,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
146 mv_Action_first_time = errno = 0; 145 mv_Action_first_time = errno = 0;
147 if (rename(fileName, destName) < 0 && errno != EXDEV) { 146 if (rename(fileName, destName) < 0 && errno != EXDEV) {
148 fprintf(stderr, "%s: rename(%s, %s): %s\n", 147 fprintf(stderr, "%s: rename(%s, %s): %s\n",
149 dz, fileName, destName, strerror(errno)); 148 applet_name, fileName, destName, strerror(errno));
150 goto do_copyFile; /* Try anyway... */ 149 goto do_copyFile; /* Try anyway... */
151 } 150 }
152 else if (errno == EXDEV) 151 else if (errno == EXDEV)
@@ -159,7 +158,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
159 if (is_in_ino_dev_hashtable(statbuf, &name)) { 158 if (is_in_ino_dev_hashtable(statbuf, &name)) {
160 if (link(name, destName) < 0) { 159 if (link(name, destName) < 0) {
161 fprintf(stderr, "%s: link(%s, %s): %s\n", 160 fprintf(stderr, "%s: link(%s, %s): %s\n",
162 dz, name, destName, strerror(errno)); 161 applet_name, name, destName, strerror(errno));
163 return FALSE; 162 return FALSE;
164 } 163 }
165 return TRUE; 164 return TRUE;
@@ -178,11 +177,11 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
178 177
179 if (S_ISDIR(statbuf->st_mode)) { 178 if (S_ISDIR(statbuf->st_mode)) {
180 if (rmdir(fileName) < 0) { 179 if (rmdir(fileName) < 0) {
181 fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno)); 180 fprintf(stderr, "%s: rmdir(%s): %s\n", applet_name, fileName, strerror(errno));
182 status = FALSE; 181 status = FALSE;
183 } 182 }
184 } else if (unlink(fileName) < 0) { 183 } else if (unlink(fileName) < 0) {
185 fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno)); 184 fprintf(stderr, "%s: unlink(%s): %s\n", applet_name, fileName, strerror(errno));
186 status = FALSE; 185 status = FALSE;
187 } 186 }
188 return status; 187 return status;
@@ -190,8 +189,7 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
190 189
191extern int cp_mv_main(int argc, char **argv) 190extern int cp_mv_main(int argc, char **argv)
192{ 191{
193 dz = *argv; /* already basename'd by busybox.c:main */ 192 if (*applet_name == 'c' && *(applet_name + 1) == 'p')
194 if (*dz == 'c' && *(dz + 1) == 'p')
195 dz_i = is_cp; 193 dz_i = is_cp;
196 else 194 else
197 dz_i = is_mv; 195 dz_i = is_mv;
@@ -276,20 +274,20 @@ extern int cp_mv_main(int argc, char **argv)
276 char *pushd, *d, *p; 274 char *pushd, *d, *p;
277 275
278 if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) { 276 if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
279 fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno)); 277 fprintf(stderr, "%s: getcwd(): %s\n", applet_name, strerror(errno));
280 continue; 278 continue;
281 } 279 }
282 if (chdir(baseDestName) < 0) { 280 if (chdir(baseDestName) < 0) {
283 fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno)); 281 fprintf(stderr, "%s: chdir(%s): %s\n", applet_name, baseSrcName, strerror(errno));
284 continue; 282 continue;
285 } 283 }
286 if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) { 284 if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
287 fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno)); 285 fprintf(stderr, "%s: getcwd(): %s\n", applet_name, strerror(errno));
288 continue; 286 continue;
289 } 287 }
290 while (!state && *d != '\0') { 288 while (!state && *d != '\0') {
291 if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */ 289 if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
292 fprintf(stderr, "%s: stat(%s) :%s\n", dz, d, strerror(errno)); 290 fprintf(stderr, "%s: stat(%s) :%s\n", applet_name, d, strerror(errno));
293 state = -1; 291 state = -1;
294 continue; 292 continue;
295 } 293 }
@@ -298,7 +296,7 @@ extern int cp_mv_main(int argc, char **argv)
298 fprintf(stderr, 296 fprintf(stderr,
299 "%s: Cannot %s `%s' " 297 "%s: Cannot %s `%s' "
300 "into a subdirectory of itself, `%s/%s'\n", 298 "into a subdirectory of itself, `%s/%s'\n",
301 dz, dz, baseSrcName, baseDestName, baseSrcName); 299 applet_name, applet_name, baseSrcName, baseDestName, baseSrcName);
302 state = -1; 300 state = -1;
303 continue; 301 continue;
304 } 302 }
@@ -307,7 +305,7 @@ extern int cp_mv_main(int argc, char **argv)
307 } 305 }
308 } 306 }
309 if (chdir(pushd) < 0) { 307 if (chdir(pushd) < 0) {
310 fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno)); 308 fprintf(stderr, "%s: chdir(%s): %s\n", applet_name, pushd, strerror(errno));
311 free(pushd); 309 free(pushd);
312 free(d); 310 free(d);
313 continue; 311 continue;