From 1bad91549843a944631f5fffc702b87c39b06599 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sat, 3 Aug 2019 08:01:54 -0400 Subject: rename rm_prompt() to confirm(); remove redundant variable --- rm.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rm.c b/rm.c index 6d92815..5af4415 100644 --- a/rm.c +++ b/rm.c @@ -43,10 +43,10 @@ static enum { DEFAULT, INTERACTIVE, FORCE } mode = DEFAULT; static int recursive = 0; static int retval = 0; -static int rm_prompt(const char *p) +static int confirm(const char *p) { static regex_t yesre = { 0 }; - static int compiled = 0; + static char *yesexpr = NULL; if (mode == FORCE) { return 1; @@ -61,10 +61,9 @@ static int rm_prompt(const char *p) char buf[MAX_CANON]; fgets(buf, sizeof(buf), stdin); - if (!compiled) { - char *yesexpr = nl_langinfo(YESEXPR); + if (yesexpr == NULL) { + yesexpr = nl_langinfo(YESEXPR); regcomp(&yesre, yesexpr, REG_EXTENDED | REG_ICASE | REG_NOSUB); - compiled = 1; } if (regexec(&yesre, buf, 0, NULL, 0) == 0) { @@ -86,12 +85,12 @@ int rm(const char *p, const struct stat *st, int typeflag, struct FTW *f) if (!recursive) { fprintf(stderr, "rm: %s: %s\n", p, strerror(EISDIR)); retval = 1; - } else if (rm_prompt(p) && rmdir(p) != 0) { + } else if (confirm(p) && rmdir(p) != 0) { fprintf(stderr, "rm: %s: %s\n", p, strerror(errno)); retval = 1; } - } else if (rm_prompt(p) && unlink(p) != 0) { + } else if (confirm(p) && unlink(p) != 0) { fprintf(stderr, "rm: %s: %s\n", p, strerror(errno)); retval = 1; } -- cgit v1.2.1