* 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 <unistd.h>
#include <errno.h>
#include <getopt.h>
+#include <stdlib.h>
-#define is_cp 0
-#define is_mv 1
+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 */
static int srcDirFlag;
static struct stat srcStatBuf;
-static char baseDestName[BUFSIZ + 1];
+static char *pBaseDestName;
static size_t baseDestLen;
static int destDirFlag;
static struct stat destStatBuf;
const char *srcBasename;
char *name;
- strcpy(destName, baseDestName);
+ strcpy(destName, pBaseDestName);
destLen = strlen(destName);
if (srcDirFlag == TRUE) {
if (mv_Action_first_time && (dz_i == is_mv)) {
mv_Action_first_time = errno = 0;
if (rename(fileName, destName) < 0 && errno != EXDEV) {
- error_msg("rename(%s, %s): %s\n", fileName, destName,
- strerror(errno));
+ perror_msg("rename(%s, %s)", fileName, destName);
goto do_copyFile; /* Try anyway... */
}
else if (errno == EXDEV)
if (preserveFlag == TRUE && statbuf->st_nlink > 1) {
if (is_in_ino_dev_hashtable(statbuf, &name)) {
if (link(name, destName) < 0) {
- error_msg("link(%s, %s): %s\n", name, destName, strerror(errno));
+ perror_msg("link(%s, %s)", name, destName);
return FALSE;
}
return TRUE;
if (S_ISDIR(statbuf->st_mode)) {
if (rmdir(fileName) < 0) {
- error_msg("rmdir(%s): %s\n", fileName, strerror(errno));
+ perror_msg("rmdir(%s)", fileName);
status = FALSE;
}
} else if (unlink(fileName) < 0) {
- error_msg("unlink(%s): %s\n", fileName, strerror(errno));
+ perror_msg("unlink(%s)", fileName);
status = FALSE;
}
return status;
{
volatile int i;
int c;
+ RESERVE_BB_BUFFER(baseDestName,BUFSIZ + 1);
+ pBaseDestName = baseDestName; /* available globally */
if (*applet_name == 'c' && *(applet_name + 1) == 'p')
dz_i = is_cp;
char *pushd, *d, *p;
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
- error_msg("getcwd(): %s\n", strerror(errno));
+ perror_msg("getcwd()");
continue;
}
if (chdir(baseDestName) < 0) {
- error_msg("chdir(%s): %s\n", baseSrcName, strerror(errno));
+ perror_msg("chdir(%s)", baseSrcName);
continue;
}
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
- error_msg("getcwd(): %s\n", strerror(errno));
+ perror_msg("getcwd()");
continue;
}
while (!state && *d != '\0') {
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
- error_msg("stat(%s): %s\n", d, strerror(errno));
+ perror_msg("stat(%s)", d);
state = -1;
continue;
}
}
}
if (chdir(pushd) < 0) {
- error_msg("chdir(%s): %s\n", pushd, strerror(errno));
+ perror_msg("chdir(%s)", pushd);
free(pushd);
free(d);
continue;