summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-25 07:00:21 -0500
committerKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-25 07:00:21 -0500
commit1bf49d076dabfec6f386558ae10ced1aa4e94643 (patch)
tree06e80945ea1d21fd5f6dbabcd391338274d4c0c3
parent7bc239af5ee1313724117dd43d022c6b52331250 (diff)
downloaduserland-1bf49d076dabfec6f386558ae10ced1aa4e94643.tar.gz
userland-1bf49d076dabfec6f386558ae10ced1aa4e94643.tar.bz2
userland-1bf49d076dabfec6f386558ae10ced1aa4e94643.tar.xz
userland-1bf49d076dabfec6f386558ae10ced1aa4e94643.zip
bin/rm: make buildable with libbsd
-rw-r--r--bin/rm/rm.c50
1 files changed, 19 insertions, 31 deletions
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 <sys/cdefs.h>
-#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 <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -57,7 +43,9 @@ __RCSID("$NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $");
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <bsd/stdlib.h>
#include <string.h>
+#include <bsd/string.h>
#include <unistd.h>
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++;