Add errno.h
[oweals/busybox.git] / rm.c
diff --git a/rm.c b/rm.c
index 275c059463487ff73175faabff4a9a46cc594706..a9501ec7f004c23277b5c913c0657c5f1c8da1d2 100644 (file)
--- a/rm.c
+++ b/rm.c
@@ -22,7 +22,7 @@
  *
  */
 
-#include "internal.h"
+#include "busybox.h"
 #include <stdio.h>
 #include <time.h>
 #include <utime.h>
@@ -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);
+               perror_msg("%s", fileName);
                return (FALSE);
        }
        return (TRUE);
@@ -45,8 +45,13 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 
 static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
 {
+       if (recursiveFlag == FALSE) {
+               errno = EISDIR;
+               perror_msg("%s", fileName);
+               return (FALSE);
+       } 
        if (rmdir(fileName) < 0) {
-               perror(fileName);
+               perror_msg("%s", fileName);
                return (FALSE);
        }
        return (TRUE);
@@ -54,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;
 
@@ -95,11 +101,11 @@ extern int rm_main(int argc, char **argv)
                        && errno == ENOENT) {
                        /* do not reports errors for non-existent files if -f, just skip them */
                } else {
-                       if (recursiveAction(srcName, recursiveFlag, FALSE,
+                       if (recursive_action(srcName, recursiveFlag, FALSE,
                                                                TRUE, fileAction, dirAction, NULL) == FALSE) {
-                               exit(FALSE);
+                               status = EXIT_FAILURE;
                        }
                }
        }
-       return(TRUE);
+       return status;
 }