diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-03 08:01:54 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-03 08:01:54 -0400 |
commit | 1bad91549843a944631f5fffc702b87c39b06599 (patch) | |
tree | 1fadb5e9a4f184d8a3e6e8cb52ccece39e473cf9 /rm.c | |
parent | fe0c0688c3cdeeadc5c37f008cf3b8481162fb4f (diff) |
rename rm_prompt() to confirm(); remove redundant variable
Diffstat (limited to 'rm.c')
-rw-r--r-- | rm.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -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; } |