summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen1999-10-17 05:43:39 +0000
committerEric Andersen1999-10-17 05:43:39 +0000
commit9b5871888989b16f94cbba5dd304ac444def3afd (patch)
tree17187e3f6988830c0e329378e552995d083080ed
parentcb6e25655f894c90e4befc4bee0e66794dd6858f (diff)
downloadbusybox-9b5871888989b16f94cbba5dd304ac444def3afd.zip
busybox-9b5871888989b16f94cbba5dd304ac444def3afd.tar.gz
Some fixes and such
-rw-r--r--chmod_chown_chgrp.c23
-rw-r--r--coreutils/cp.c14
-rw-r--r--coreutils/mv.c7
-rw-r--r--cp.c14
-rw-r--r--find.c8
-rw-r--r--findutils/find.c8
-rw-r--r--internal.h4
-rw-r--r--mv.c7
-rw-r--r--utility.c15
9 files changed, 50 insertions, 50 deletions
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index 5c2adab..f3d8ce2 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -49,20 +49,17 @@ static const char chmod_usage[] = "[-R] MODE[,MODE]... FILE...\n"
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
- struct stat statBuf;
- if (stat(fileName, &statBuf) < 0) {
- switch (whichApp) {
- case CHGRP_APP:
- case CHOWN_APP:
- if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0)
- return( TRUE);
- case CHMOD_APP:
- fprintf(stderr, "%s, %d\n", fileName, mode);
- if (chmod(fileName, mode))
- return( TRUE);
- }
+ switch (whichApp) {
+ case CHGRP_APP:
+ case CHOWN_APP:
+ if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statbuf->st_uid), gid) < 0)
+ return( TRUE);
+ case CHMOD_APP:
+ fprintf(stderr, "%s, %d\n", fileName, mode);
+ if (chmod(fileName, mode))
+ return( TRUE);
}
perror(fileName);
return( FALSE);
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 6ca66e6..4016fc7 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -41,21 +41,24 @@ static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static const char *skipName;
+static int dirFlag = FALSE;
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
- strcat(newdestName, strstr(fileName, skipName));
+ if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
+ strcat(newdestName, "/");
+ if ( skipName != NULL)
+ strcat(newdestName, strstr(fileName, skipName));
+ }
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
- int dirFlag;
-
if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage);
exit (FALSE);
@@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv)
destName = argv[argc - 1];
-
dirFlag = isDirectory(destName);
- if ((argc > 3) && !dirFlag) {
+ if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
diff --git a/coreutils/mv.c b/coreutils/mv.c
index df56206..10a0822 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -41,7 +41,7 @@ extern int mv_main (int argc, char **argv)
if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
- return (FALSE);
+ exit (FALSE);
}
lastArg = argv[argc - 1];
@@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv)
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
-
- return (FALSE);
+ exit (FALSE);
}
while (argc-- > 2) {
@@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv)
if (unlink (srcName) < 0)
perror (srcName);
}
- return (TRUE);
+ exit (TRUE);
}
diff --git a/cp.c b/cp.c
index 6ca66e6..4016fc7 100644
--- a/cp.c
+++ b/cp.c
@@ -41,21 +41,24 @@ static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static const char *skipName;
+static int dirFlag = FALSE;
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
- strcat(newdestName, strstr(fileName, skipName));
+ if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
+ strcat(newdestName, "/");
+ if ( skipName != NULL)
+ strcat(newdestName, strstr(fileName, skipName));
+ }
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
- int dirFlag;
-
if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage);
exit (FALSE);
@@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv)
destName = argv[argc - 1];
-
dirFlag = isDirectory(destName);
- if ((argc > 3) && !dirFlag) {
+ if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
diff --git a/find.c b/find.c
index d618401..c92202b 100644
--- a/find.c
+++ b/find.c
@@ -35,7 +35,7 @@ static const char find_usage[] = "find [path...] [expression]\n"
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
if (pattern==NULL)
fprintf(stdout, "%s\n", fileName);
@@ -44,7 +44,7 @@ static int fileAction(const char *fileName)
return( TRUE);
}
-static int dirAction(const char *fileName)
+static int dirAction(const char *fileName, struct stat* statbuf)
{
DIR *dir;
struct dirent *entry;
@@ -70,7 +70,7 @@ static int dirAction(const char *fileName)
int find_main(int argc, char **argv)
{
if (argc <= 1) {
- dirAction( ".");
+ dirAction( ".", NULL);
}
/* peel off the "find" */
@@ -120,7 +120,7 @@ int find_main(int argc, char **argv)
break;
}
- dirAction( directory);
+ dirAction( directory, NULL);
exit(TRUE);
}
diff --git a/findutils/find.c b/findutils/find.c
index d618401..c92202b 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -35,7 +35,7 @@ static const char find_usage[] = "find [path...] [expression]\n"
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
if (pattern==NULL)
fprintf(stdout, "%s\n", fileName);
@@ -44,7 +44,7 @@ static int fileAction(const char *fileName)
return( TRUE);
}
-static int dirAction(const char *fileName)
+static int dirAction(const char *fileName, struct stat* statbuf)
{
DIR *dir;
struct dirent *entry;
@@ -70,7 +70,7 @@ static int dirAction(const char *fileName)
int find_main(int argc, char **argv)
{
if (argc <= 1) {
- dirAction( ".");
+ dirAction( ".", NULL);
}
/* peel off the "find" */
@@ -120,7 +120,7 @@ int find_main(int argc, char **argv)
break;
}
- dirAction( directory);
+ dirAction( directory, NULL);
exit(TRUE);
}
diff --git a/internal.h b/internal.h
index 397eca4..4650e9f 100644
--- a/internal.h
+++ b/internal.h
@@ -122,8 +122,8 @@ void freeChunks(void);
int fullWrite(int fd, const char *buf, int len);
int fullRead(int fd, char *buf, int len);
int recursiveAction(const char *fileName, int recurse, int followLinks,
- int (*fileAction) (const char *fileName),
- int (*dirAction) (const char *fileName));
+ int (*fileAction) (const char *fileName, struct stat* statbuf),
+ int (*dirAction) (const char *fileName, struct stat* statbuf));
int match(const char* text, const char * pattern);
const char* timeString(time_t timeVal);
diff --git a/mv.c b/mv.c
index df56206..10a0822 100644
--- a/mv.c
+++ b/mv.c
@@ -41,7 +41,7 @@ extern int mv_main (int argc, char **argv)
if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
- return (FALSE);
+ exit (FALSE);
}
lastArg = argv[argc - 1];
@@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv)
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
-
- return (FALSE);
+ exit (FALSE);
}
while (argc-- > 2) {
@@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv)
if (unlink (srcName) < 0)
perror (srcName);
}
- return (TRUE);
+ exit (TRUE);
}
diff --git a/utility.c b/utility.c
index cf90f37..4bb479f 100644
--- a/utility.c
+++ b/utility.c
@@ -46,8 +46,9 @@ int isDirectory(const char *name)
if (stat(name, &statBuf) < 0)
return FALSE;
-
- return S_ISDIR(statBuf.st_mode);
+ if (S_ISDIR(statBuf.st_mode))
+ return TRUE;
+ return(FALSE);
}
@@ -467,8 +468,8 @@ int fullRead(int fd, char *buf, int len)
*/
int
recursiveAction(const char *fileName, int recurse, int followLinks,
- int (*fileAction) (const char *fileName),
- int (*dirAction) (const char *fileName))
+ int (*fileAction) (const char *fileName, struct stat* statbuf),
+ int (*dirAction) (const char *fileName, struct stat* statbuf))
{
int status;
struct stat statbuf;
@@ -487,7 +488,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
if (recurse == FALSE) {
if (S_ISDIR(statbuf.st_mode)) {
if (dirAction != NULL)
- return (dirAction(fileName));
+ return (dirAction(fileName, &statbuf));
else
return (TRUE);
}
@@ -501,7 +502,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
return (FALSE);
}
if (dirAction != NULL) {
- status = dirAction(fileName);
+ status = dirAction(fileName, &statbuf);
if (status == FALSE) {
perror(fileName);
return (FALSE);
@@ -531,7 +532,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
if (fileAction == NULL)
return (TRUE);
else
- return (fileAction(fileName));
+ return (fileAction(fileName, &statbuf));
}
return (TRUE);
}