summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-24 22:52:48 -0500
committerKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-24 22:52:48 -0500
commit2b6d352202dcdafeb03ddc7be9d45d54915afab4 (patch)
tree51004afbbc547858568ed36e2517f10b90cfc6db /bin
parentefd279db50eed5ccab8d56c3509ca2658d5b389d (diff)
downloaduserland-2b6d352202dcdafeb03ddc7be9d45d54915afab4.tar.gz
userland-2b6d352202dcdafeb03ddc7be9d45d54915afab4.tar.bz2
userland-2b6d352202dcdafeb03ddc7be9d45d54915afab4.tar.xz
userland-2b6d352202dcdafeb03ddc7be9d45d54915afab4.zip
bin/mv: make buildable with libbsd
Diffstat (limited to 'bin')
-rw-r--r--bin/mv/mv.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index e318d48..4b8af74 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -32,25 +32,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
-#else
-__RCSID("$NetBSD: mv.c,v 1.45 2016/02/28 10:59:29 mrg Exp $");
-#endif
-#endif /* not lint */
-
#include <sys/param.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/stat.h>
-#include <sys/extattr.h>
+#include <sys/ioctl.h>
+
+#include <linux/fs.h>
#include <err.h>
#include <errno.h>
@@ -60,7 +48,9 @@ __RCSID("$NetBSD: mv.c,v 1.45 2016/02/28 10:59:29 mrg Exp $");
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <bsd/stdlib.h>
#include <string.h>
+#include <bsd/string.h>
#include <unistd.h>
#include "pathnames.h"
@@ -72,10 +62,10 @@ static sig_atomic_t pinfo;
static int copy(char *, char *);
static int do_move(char *, char *);
static int fastcopy(char *, char *, struct stat *);
-__dead static void usage(void);
+static void usage(void);
static void
-progress(int sig __unused)
+progress(int sig)
{
pinfo++;
@@ -117,7 +107,7 @@ main(int argc, char *argv[])
stdin_ok = isatty(STDIN_FILENO);
- (void)signal(SIGINFO, progress);
+ (void)signal(SIGHUP, progress);
/*
* If the stat on the target fails or the target isn't a directory,
@@ -190,6 +180,8 @@ do_move(char *from, char *to)
}
(void)fprintf(stderr, "overwrite %s? ", to);
} else if (stdin_ok && access(to, W_OK) && !stat(to, &sb)) {
+ struct passwd *user = getpwuid(sb.st_uid);
+ struct group *group = getgrgid(sb.st_gid);
if (access(from, F_OK)) {
warn("rename %s", from);
return (1);
@@ -197,8 +189,8 @@ do_move(char *from, char *to)
strmode(sb.st_mode, modep);
(void)fprintf(stderr, "override %s%s%s/%s for %s? ",
modep + 1, modep[9] == ' ' ? "" : " ",
- user_from_uid(sb.st_uid, 0),
- group_from_gid(sb.st_gid, 0), to);
+ user != NULL ? user->pw_name : "",
+ group != NULL ? group->gr_name : "", to);
} else
ask = 0;
if (ask) {
@@ -262,6 +254,24 @@ do_move(char *from, char *to)
fastcopy(from, to, &sb) : copy(from, to));
}
+#ifndef HAVE_FCPXATTR
+int
+fcpxattr(int from_fd, int to_fd)
+{
+ int attr, from_ret, to_ret;
+
+ from_ret = ioctl(from_fd, FS_IOC_GETFLAGS, &attr);
+ if (from_ret != 0) {
+ return from_ret;
+ }
+ to_ret = ioctl(to_ret, FS_IOC_SETFLAGS, &attr);
+ if (to_ret != 0) {
+ return to_ret;
+ }
+ return 0;
+}
+#endif
+
static int
fastcopy(char *from, char *to, struct stat *sbp)
{
@@ -272,7 +282,7 @@ fastcopy(char *from, char *to, struct stat *sbp)
#endif
static blksize_t blen;
static char *bp;
- int from_fd, to_fd;
+ int from_fd, to_fd, attrs;
ssize_t nread;
off_t total = 0;
@@ -293,6 +303,11 @@ fastcopy(char *from, char *to, struct stat *sbp)
(void)close(to_fd);
return (1);
}
+
+ if (ioctl(from_fd, FS_IOC_GETFLAGS, &attrs) == -1) {
+ warn("%s: unable to read file attributes: %s", from, strerror(errno));
+ }
+
while ((nread = read(from_fd, bp, blen)) > 0) {
if (write(to_fd, bp, nread) != nread) {
warn("%s", to);
@@ -352,8 +367,9 @@ err: if (unlink(to))
}
if (fchmod(to_fd, sbp->st_mode))
warn("%s: set mode", to);
- if (fchflags(to_fd, sbp->st_flags) && (errno != EOPNOTSUPP))
- warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
+ if (ioctl(to_fd, FS_IOC_SETFLAGS, &attrs) == -1) {
+ warn("%s: unable to set file attributes: %s", to, strerror(errno));
+ }
if (close(to_fd)) {
warn("%s", to);