OSDN Git Service

Some fixes and such
authorEric Andersen <andersen@codepoet.org>
Sun, 17 Oct 1999 05:43:39 +0000 (05:43 -0000)
committerEric Andersen <andersen@codepoet.org>
Sun, 17 Oct 1999 05:43:39 +0000 (05:43 -0000)
chmod_chown_chgrp.c
coreutils/cp.c
coreutils/mv.c
cp.c
find.c
findutils/find.c
internal.h
mv.c
utility.c

index 5c2adab..f3d8ce2 100644 (file)
@@ -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);
index 6ca66e6..4016fc7 100644 (file)
@@ -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);
     }
index df56206..10a0822 100644 (file)
@@ -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 (file)
--- 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 (file)
--- 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);
 }
 
index d618401..c92202b 100644 (file)
@@ -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);
 }
 
index 397eca4..4650e9f 100644 (file)
@@ -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 (file)
--- 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);
 }
index cf90f37..4bb479f 100644 (file)
--- 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);
 }