From 9d6d971d463053417e18e01095cc3c7bf722f892 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Sat, 11 May 2019 21:36:41 -0500 Subject: bin/cp: make buildable via libbsd --- bin/cp/utils.c | 58 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) (limited to 'bin/cp/utils.c') diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 6275fc6..8685408 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -29,20 +29,12 @@ * SUCH DAMAGE. */ -#include -#ifndef lint -#if 0 -static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; -#else -__RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); -#endif -#endif /* not lint */ - #include #include #include #include -#include +#include +#include #include #include @@ -51,24 +43,44 @@ __RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); #include #include #include +#include #include #include +#include #include "extern.h" #define MMAP_MAX_SIZE (8 * 1048576) #define MMAP_MAX_WRITE (64 * 1024) +#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 + int set_utimes(const char *file, struct stat *fs) { struct timespec ts[2]; - ts[0] = fs->st_atimespec; - ts[1] = fs->st_mtimespec; + ts[0] = fs->st_atim; + ts[1] = fs->st_mtim; - if (lutimens(file, ts)) { - warn("lutimens: %s", file); + if (utimensat(AT_FDCWD, file, ts, AT_SYMLINK_NOFOLLOW)) { + warn("utimensat: %s", file); return (1); } return (0); @@ -383,24 +395,6 @@ setfile(struct stat *fs, int fd) rval = 1; } - if (!islink && !Nflag) { - unsigned long fflags = fs->st_flags; - /* - * XXX - * NFS doesn't support chflags; ignore errors unless - * there's reason to believe we're losing bits. - * (Note, this still won't be right if the server - * supports flags and we were trying to *remove* flags - * on a file that we copied, i.e., that we didn't create.) - */ - errno = 0; - if ((fd ? fchflags(fd, fflags) : - chflags(to.p_path, fflags)) == -1) - if (errno != EOPNOTSUPP || fs->st_flags != 0) { - warn("chflags: %s", to.p_path); - rval = 1; - } - } /* if fd is non-zero, caller must call set_utimes() after close() */ if (fd == 0 && set_utimes(to.p_path, fs)) rval = 1; -- cgit v1.2.3-60-g2f50