summaryrefslogtreecommitdiff
path: root/usr/src/cmd/rm/rm.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/rm/rm.c')
-rw-r--r--usr/src/cmd/rm/rm.c47
1 files changed, 12 insertions, 35 deletions
diff --git a/usr/src/cmd/rm/rm.c b/usr/src/cmd/rm/rm.c
index 95b9cd766e..2e779280df 100644
--- a/usr/src/cmd/rm/rm.c
+++ b/usr/src/cmd/rm/rm.c
@@ -47,6 +47,7 @@
#include <string.h>
#include <unistd.h>
#include <values.h>
+#include "getresponse.h"
#define E_OK 010 /* make __accessat() use effective ids */
@@ -71,9 +72,6 @@ static struct dlist top = {
DIR_CANTCLOSE,
};
-static char yeschr[SCHAR_MAX + 2];
-static char nochr[SCHAR_MAX + 2];
-
static struct dlist *cur, *rec;
static int rm(const char *, struct dlist *);
@@ -103,9 +101,6 @@ main(int argc, char **argv)
#endif
(void) textdomain(TEXT_DOMAIN);
- (void) strncpy(yeschr, nl_langinfo(YESSTR), SCHAR_MAX + 1);
- (void) strncpy(nochr, nl_langinfo(NOSTR), SCHAR_MAX + 1);
-
while ((c = getopt(argc, argv, "frRi")) != EOF)
switch (c) {
case 'f':
@@ -161,6 +156,12 @@ main(int argc, char **argv)
if (pathbuf == NULL)
memerror();
+ if (init_yes() < 0) {
+ (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES),
+ strerror(errno));
+ exit(2);
+ }
+
for (; *argv != NULL; argv++) {
char *p = strrchr(*argv, '/');
if (p == NULL)
@@ -371,7 +372,7 @@ rm(const char *entry, struct dlist *caller)
*/
if (interactive && !confirm(stderr,
gettext("rm: examine files in directory %s (%s/%s)? "),
- pathbuf, yeschr, nochr)) {
+ pathbuf, yesstr, nostr)) {
return (0);
}
@@ -390,7 +391,7 @@ rm(const char *entry, struct dlist *caller)
__accessat(caller->fd, entry, W_OK|X_OK|E_OK) != 0 &&
!confirm(stderr,
gettext("rm: examine files in directory %s (%s/%s)? "),
- pathbuf, yeschr, nochr)) {
+ pathbuf, yesstr, nostr)) {
return (0);
}
#endif
@@ -424,7 +425,7 @@ rm(const char *entry, struct dlist *caller)
*/
if (!confirm(stderr,
gettext("rm: remove %s (%s/%s)? "),
- pathbuf, yeschr, nochr)) {
+ pathbuf, yesstr, nostr)) {
errcnt++;
return (0);
}
@@ -500,7 +501,7 @@ unlinkit:
*/
if (interactive) {
if (!confirm(stderr, gettext("rm: remove %s (%s/%s)? "),
- pathbuf, yeschr, nochr)) {
+ pathbuf, yesstr, nostr)) {
return (0);
}
} else if (!silent && flag == 0) {
@@ -523,7 +524,7 @@ unlinkit:
__accessat(caller->fd, entry, W_OK|E_OK) != 0 &&
!confirm(stdout,
gettext("rm: %s: override protection %o (%s/%s)? "),
- pathbuf, temp.st_mode & 0777, yeschr, nochr)) {
+ pathbuf, temp.st_mode & 0777, yesstr, nostr)) {
return (0);
}
}
@@ -564,30 +565,6 @@ unlinkit:
}
static int
-yes(void)
-{
- int i, b;
- char ans[SCHAR_MAX + 1];
-
- for (i = 0; ; i++) {
- b = getchar();
- if (b == '\n' || b == '\0' || b == EOF) {
- ans[i] = 0;
- break;
- }
- if (i < SCHAR_MAX)
- ans[i] = (char)b;
- }
- if (i >= SCHAR_MAX) {
- i = SCHAR_MAX;
- ans[SCHAR_MAX] = 0;
- }
- if ((i == 0) | (strncmp(yeschr, ans, i)))
- return (0);
- return (1);
-}
-
-static int
confirm(FILE *fp, const char *q, ...)
{
va_list ap;