From 1bf49d076dabfec6f386558ae10ced1aa4e94643 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Sat, 25 May 2019 07:00:21 -0500 Subject: bin/rm: make buildable with libbsd --- bin/rm/rm.c | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'bin') diff --git a/bin/rm/rm.c b/bin/rm/rm.c index c1d2e8d..4989460 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -29,20 +29,6 @@ * SUCH DAMAGE. */ -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95"; -#else -__RCSID("$NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $"); -#endif -#endif /* not lint */ - #include #include #include @@ -57,7 +43,9 @@ __RCSID("$NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $"); #include #include #include +#include #include +#include #include static int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag; @@ -70,7 +58,7 @@ static void progress(int); static void rm_file(char **); static int rm_overwrite(char *, struct stat *); static void rm_tree(char **); -__dead static void usage(void); +static void usage(void); /* * For the sake of the `-f' flag, check whether an error number indicates the @@ -138,7 +126,7 @@ main(int argc, char *argv[]) usage(); } - (void)signal(SIGINFO, progress); + (void)signal(SIGHUP, progress); checkdot(argv); @@ -244,12 +232,6 @@ rm_tree(char **argv) continue; break; - case FTS_W: - rval = undelete(p->fts_accpath); - if (rval != 0 && fflag && errno == ENOENT) - continue; - break; - default: if (Pflag) { if (rm_overwrite(p->fts_accpath, NULL)) @@ -288,7 +270,7 @@ rm_file(char **argv) /* Assume if can't stat the file, can't unlink it. */ if (lstat(f, &sb)) { if (Wflag) { - sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR; + sb.st_mode = S_IWUSR|S_IRUSR; } else { if (!fflag || !NONEXISTENT(errno)) { warn("%s", f); @@ -307,11 +289,7 @@ rm_file(char **argv) eval = 1; continue; } - if (!fflag && !S_ISWHT(sb.st_mode) && !check(f, f, &sb)) - continue; - if (S_ISWHT(sb.st_mode)) - rval = undelete(f); - else if (S_ISDIR(sb.st_mode)) + if (S_ISDIR(sb.st_mode)) rval = rmdir(f); else { if (Pflag) { @@ -519,6 +497,9 @@ check(char *path, char *name, struct stat *sp) { int ch, first; char modep[15]; + struct passwd *user; + struct group *group; + char username[10], groupname[10]; /* Check -i first. */ if (iflag) @@ -540,10 +521,17 @@ check(char *path, char *name, struct stat *sp) " be overwritten", path); return 0; } + user = getpwuid(sp->st_uid); + group = getgrgid(sp->st_gid); + if (user == NULL) { + snprintf(username, 10, "%d", sp->st_uid); + } + if (group == NULL) { + snprintf(groupname, 10, "%d", sp->st_gid); + } (void)fprintf(stderr, "override %s%s%s:%s for '%s'? ", modep + 1, modep[9] == ' ' ? "" : " ", - user_from_uid(sp->st_uid, 0), - group_from_gid(sp->st_gid, 0), path); + username, groupname, path); } (void)fflush(stderr); @@ -604,7 +592,7 @@ usage(void) } static void -progress(int sig __unused) +progress(int sig) { pinfo++; -- cgit v1.2.3-60-g2f50