Use perrorMsg instead of perror and keep removing files if we encounter
authorMatt Kraai <kraai@debian.org>
Tue, 5 Dec 2000 05:11:41 +0000 (05:11 -0000)
committerMatt Kraai <kraai@debian.org>
Tue, 5 Dec 2000 05:11:41 +0000 (05:11 -0000)
an error.

coreutils/rm.c
rm.c
utility.c

index c62083e9b940603088af0b7ea0e2efa46e62b687..5663351588ea5df39886ba1f25e3c8c01c8a0a5b 100644 (file)
@@ -37,7 +37,7 @@ static const char *srcName;
 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 {
        if (unlink(fileName) < 0) {
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return (FALSE);
        }
        return (TRUE);
@@ -47,11 +47,11 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
 {
        if (recursiveFlag == FALSE) {
                errno = EISDIR;
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return (FALSE);
        } 
        if (rmdir(fileName) < 0) {
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return (FALSE);
        }
        return (TRUE);
@@ -59,6 +59,7 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
 
 extern int rm_main(int argc, char **argv)
 {
+       int status = EXIT_SUCCESS;
        int stopIt=FALSE;
        struct stat statbuf;
 
@@ -102,9 +103,9 @@ extern int rm_main(int argc, char **argv)
                } else {
                        if (recursiveAction(srcName, recursiveFlag, FALSE,
                                                                TRUE, fileAction, dirAction, NULL) == FALSE) {
-                               return EXIT_FAILURE;
+                               status = EXIT_FAILURE;
                        }
                }
        }
-       return EXIT_SUCCESS;
+       return status;
 }
diff --git a/rm.c b/rm.c
index c62083e9b940603088af0b7ea0e2efa46e62b687..5663351588ea5df39886ba1f25e3c8c01c8a0a5b 100644 (file)
--- a/rm.c
+++ b/rm.c
@@ -37,7 +37,7 @@ static const char *srcName;
 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 {
        if (unlink(fileName) < 0) {
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return (FALSE);
        }
        return (TRUE);
@@ -47,11 +47,11 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
 {
        if (recursiveFlag == FALSE) {
                errno = EISDIR;
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return (FALSE);
        } 
        if (rmdir(fileName) < 0) {
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return (FALSE);
        }
        return (TRUE);
@@ -59,6 +59,7 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
 
 extern int rm_main(int argc, char **argv)
 {
+       int status = EXIT_SUCCESS;
        int stopIt=FALSE;
        struct stat statbuf;
 
@@ -102,9 +103,9 @@ extern int rm_main(int argc, char **argv)
                } else {
                        if (recursiveAction(srcName, recursiveFlag, FALSE,
                                                                TRUE, fileAction, dirAction, NULL) == FALSE) {
-                               return EXIT_FAILURE;
+                               status = EXIT_FAILURE;
                        }
                }
        }
-       return EXIT_SUCCESS;
+       return status;
 }
index 9ae2a8f247523b28e4205b414e07507b9d810c41..7c41ab8fb45f6ceaa3a0835db71a04f227010863 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -641,7 +641,7 @@ int recursiveAction(const char *fileName,
                                "status=%d followLinks=%d TRUE=%d\n",
                                status, followLinks, TRUE);
 #endif
-               perror(fileName);
+               perrorMsg("%s", fileName);
                return FALSE;
        }
 
@@ -666,13 +666,13 @@ int recursiveAction(const char *fileName,
 
                dir = opendir(fileName);
                if (!dir) {
-                       perror(fileName);
+                       perrorMsg("%s", fileName);
                        return FALSE;
                }
                if (dirAction != NULL && depthFirst == FALSE) {
                        status = dirAction(fileName, &statbuf, userData);
                        if (status == FALSE) {
-                               perror(fileName);
+                               perrorMsg("%s", fileName);
                                return FALSE;
                        }
                }
@@ -699,13 +699,13 @@ int recursiveAction(const char *fileName,
                }
                status = closedir(dir);
                if (status < 0) {
-                       perror(fileName);
+                       perrorMsg("%s", fileName);
                        return FALSE;
                }
                if (dirAction != NULL && depthFirst == TRUE) {
                        status = dirAction(fileName, &statbuf, userData);
                        if (status == FALSE) {
-                               perror(fileName);
+                               perrorMsg("%s", fileName);
                                return FALSE;
                        }
                }