Use perrorMsg instead of perror and keep removing files if we encounter

an error.
This commit is contained in:
Matt Kraai 2000-12-05 05:11:41 +00:00
parent 0e836ed8db
commit d27753afd9
3 changed files with 17 additions and 15 deletions

View File

@ -37,7 +37,7 @@ static const char *srcName;
static int fileAction(const char *fileName, struct stat *statbuf, void* junk) static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{ {
if (unlink(fileName) < 0) { if (unlink(fileName) < 0) {
perror(fileName); perrorMsg("%s", fileName);
return (FALSE); return (FALSE);
} }
return (TRUE); return (TRUE);
@ -47,11 +47,11 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
{ {
if (recursiveFlag == FALSE) { if (recursiveFlag == FALSE) {
errno = EISDIR; errno = EISDIR;
perror(fileName); perrorMsg("%s", fileName);
return (FALSE); return (FALSE);
} }
if (rmdir(fileName) < 0) { if (rmdir(fileName) < 0) {
perror(fileName); perrorMsg("%s", fileName);
return (FALSE); return (FALSE);
} }
return (TRUE); 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) extern int rm_main(int argc, char **argv)
{ {
int status = EXIT_SUCCESS;
int stopIt=FALSE; int stopIt=FALSE;
struct stat statbuf; struct stat statbuf;
@ -102,9 +103,9 @@ extern int rm_main(int argc, char **argv)
} else { } else {
if (recursiveAction(srcName, recursiveFlag, FALSE, if (recursiveAction(srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction, NULL) == FALSE) { TRUE, fileAction, dirAction, NULL) == FALSE) {
return EXIT_FAILURE; status = EXIT_FAILURE;
} }
} }
} }
return EXIT_SUCCESS; return status;
} }

11
rm.c
View File

@ -37,7 +37,7 @@ static const char *srcName;
static int fileAction(const char *fileName, struct stat *statbuf, void* junk) static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{ {
if (unlink(fileName) < 0) { if (unlink(fileName) < 0) {
perror(fileName); perrorMsg("%s", fileName);
return (FALSE); return (FALSE);
} }
return (TRUE); return (TRUE);
@ -47,11 +47,11 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
{ {
if (recursiveFlag == FALSE) { if (recursiveFlag == FALSE) {
errno = EISDIR; errno = EISDIR;
perror(fileName); perrorMsg("%s", fileName);
return (FALSE); return (FALSE);
} }
if (rmdir(fileName) < 0) { if (rmdir(fileName) < 0) {
perror(fileName); perrorMsg("%s", fileName);
return (FALSE); return (FALSE);
} }
return (TRUE); 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) extern int rm_main(int argc, char **argv)
{ {
int status = EXIT_SUCCESS;
int stopIt=FALSE; int stopIt=FALSE;
struct stat statbuf; struct stat statbuf;
@ -102,9 +103,9 @@ extern int rm_main(int argc, char **argv)
} else { } else {
if (recursiveAction(srcName, recursiveFlag, FALSE, if (recursiveAction(srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction, NULL) == FALSE) { TRUE, fileAction, dirAction, NULL) == FALSE) {
return EXIT_FAILURE; status = EXIT_FAILURE;
} }
} }
} }
return EXIT_SUCCESS; return status;
} }

View File

@ -641,7 +641,7 @@ int recursiveAction(const char *fileName,
"status=%d followLinks=%d TRUE=%d\n", "status=%d followLinks=%d TRUE=%d\n",
status, followLinks, TRUE); status, followLinks, TRUE);
#endif #endif
perror(fileName); perrorMsg("%s", fileName);
return FALSE; return FALSE;
} }
@ -666,13 +666,13 @@ int recursiveAction(const char *fileName,
dir = opendir(fileName); dir = opendir(fileName);
if (!dir) { if (!dir) {
perror(fileName); perrorMsg("%s", fileName);
return FALSE; return FALSE;
} }
if (dirAction != NULL && depthFirst == FALSE) { if (dirAction != NULL && depthFirst == FALSE) {
status = dirAction(fileName, &statbuf, userData); status = dirAction(fileName, &statbuf, userData);
if (status == FALSE) { if (status == FALSE) {
perror(fileName); perrorMsg("%s", fileName);
return FALSE; return FALSE;
} }
} }
@ -699,13 +699,13 @@ int recursiveAction(const char *fileName,
} }
status = closedir(dir); status = closedir(dir);
if (status < 0) { if (status < 0) {
perror(fileName); perrorMsg("%s", fileName);
return FALSE; return FALSE;
} }
if (dirAction != NULL && depthFirst == TRUE) { if (dirAction != NULL && depthFirst == TRUE) {
status = dirAction(fileName, &statbuf, userData); status = dirAction(fileName, &statbuf, userData);
if (status == FALSE) { if (status == FALSE) {
perror(fileName); perrorMsg("%s", fileName);
return FALSE; return FALSE;
} }
} }