A patch from Marc Karasek and Kanoj (kernel serial.c maintainer)
[oweals/busybox.git] / cp_mv.c
diff --git a/cp_mv.c b/cp_mv.c
index 41b981b72e3fa75e85becae7f8fb54f6ba61d6a9..3c19f1a0495bcb1f6b1989ee140ae480a0f254cf 100644 (file)
--- a/cp_mv.c
+++ b/cp_mv.c
@@ -3,7 +3,7 @@
  * Mini `cp' and `mv' implementation for BusyBox.
  *
  *
- * Copyright (C) 1999 by Lineo, inc.
+ * Copyright (C) 1999,2000,2001 by Lineo, inc.
  * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
  *
  * Copyright (C) 2000 by BitterSweet Enterprises, LLC. (GPL)
  *
  */
 
-#include "busybox.h"
-#define BB_DECLARE_EXTERN
-#define bb_need_name_too_long
-#define bb_need_omitting_directory
-#define bb_need_not_a_directory
-#include "messages.c"
-
 #include <stdio.h>
 #include <time.h>
 #include <utime.h>
 #include <errno.h>
 #include <getopt.h>
 #include <stdlib.h>
+#include "busybox.h"
+#define BB_DECLARE_EXTERN
+#define bb_need_name_too_long
+#define bb_need_omitting_directory
+#define bb_need_not_a_directory
+#include "messages.c"
+
 
 static const int is_cp = 0;
 static const int is_mv = 1;
 static int         dz_i;               /* index into cp_mv_usage */
 
-static const char *cp_mv_usage[] =     /* .rodata */
-{
-       cp_usage,
-       mv_usage
-};
 
 static int recursiveFlag;
 static int followLinks;
@@ -152,7 +147,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
                        add_to_ino_dev_hashtable(statbuf, destName);
                }
        }
-       return copy_file(fileName, destName, preserveFlag, followLinks, forceFlag);
+       return copy_file(fileName, destName, preserveFlag, followLinks, forceFlag, FALSE);
 }
 
 static int
@@ -184,7 +179,7 @@ extern int cp_mv_main(int argc, char **argv)
        else
                dz_i = is_mv;
        if (argc < 3)
-               usage(cp_mv_usage[dz_i]);
+               show_usage();
 
        if (dz_i == is_cp) {
                recursiveFlag = preserveFlag = forceFlag = FALSE;
@@ -209,11 +204,11 @@ extern int cp_mv_main(int argc, char **argv)
                                        forceFlag = TRUE;
                                        break;
                                default:
-                                       usage(cp_mv_usage[is_cp]);
+                                       show_usage();
                                }
                }
                if ((argc - optind) < 2) {
-                       usage(cp_mv_usage[dz_i]);
+                       show_usage();
                }
        } else {                                        /* (dz_i == is_mv) */
                /* Initialize optind to 1, since in libc5 optind
@@ -261,18 +256,16 @@ extern int cp_mv_main(int argc, char **argv)
                        int                     state = 0;
                        char            *pushd, *d, *p;
 
-                       if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
-                               perror_msg("getcwd()");
+                       if ((pushd = xgetcwd(0)) == NULL)
                                continue;
-                       }
+
                        if (chdir(baseDestName) < 0) {
                                perror_msg("chdir(%s)", baseSrcName);
                                continue;
                        }
-                       if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
-                               perror_msg("getcwd()");
+                       if ((d = xgetcwd(0)) == NULL)
                                continue;
-                       }
+
                        while (!state && *d != '\0') {
                                if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
                                        perror_msg("stat(%s)", d);
@@ -282,7 +275,7 @@ extern int cp_mv_main(int argc, char **argv)
                                if ((sb.st_ino == srcStatBuf.st_ino) &&
                                        (sb.st_dev == srcStatBuf.st_dev)) {
                                        error_msg("Cannot %s `%s' into a subdirectory of itself, "
-                                                       "`%s/%s'\n", applet_name, baseSrcName,
+                                                       "`%s/%s'", applet_name, baseSrcName,
                                                        baseDestName, baseSrcName);
                                        state = -1;
                                        continue;