summaryrefslogtreecommitdiff
path: root/bin/cp/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r--bin/cp/utils.c58
1 files changed, 26 insertions, 32 deletions
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 <sys/cdefs.h>
-#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 <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
-#include <sys/extattr.h>
+#include <linux/fs.h>
+#include <sys/ioctl.h>
#include <err.h>
#include <errno.h>
@@ -51,24 +43,44 @@ __RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $");
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <bsd/stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <signal.h>
#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;