* 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 <unistd.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;
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
{
volatile int i;
int c;
- char baseDestName[BUFSIZ + 1]; /* not declared globally == less bss used */
- pBaseDestName = baseDestName; /* but available globally */
+ RESERVE_BB_BUFFER(baseDestName,BUFSIZ + 1);
+ pBaseDestName = baseDestName; /* available globally */
if (*applet_name == 'c' && *(applet_name + 1) == 'p')
dz_i = is_cp;
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;
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
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);
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;