summaryrefslogtreecommitdiffstats
path: root/bin/cp/utils.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2016-04-10 15:02:29 +0000
committerjilles <jilles@FreeBSD.org>2016-04-10 15:02:29 +0000
commit4c6d087886754ec231acdbfb74a63d78cd1486d1 (patch)
tree6942e28b2d1aa08d04336edfb0404c7a93f25fdf /bin/cp/utils.c
parente29b7097a2901d2d782faabdba92b1f205958f59 (diff)
downloadFreeBSD-src-4c6d087886754ec231acdbfb74a63d78cd1486d1.zip
FreeBSD-src-4c6d087886754ec231acdbfb74a63d78cd1486d1.tar.gz
MFC r277645: cp,mv,touch: Set timestamps with nanosecond precision.
This uses utimensat().
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r--bin/cp/utils.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 0b5202e..73a3000 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -344,7 +344,7 @@ copy_special(struct stat *from_stat, int exists)
int
setfile(struct stat *fs, int fd)
{
- static struct timeval tv[2];
+ static struct timespec tspec[2];
struct stat ts;
int rval, gotstat, islink, fdval;
@@ -354,10 +354,11 @@ setfile(struct stat *fs, int fd)
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
S_IRWXU | S_IRWXG | S_IRWXO;
- TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
- TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
- if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
- warn("%sutimes: %s", islink ? "l" : "", to.p_path);
+ tspec[0] = fs->st_atim;
+ tspec[1] = fs->st_mtim;
+ if (utimensat(AT_FDCWD, to.p_path, tspec,
+ islink ? AT_SYMLINK_NOFOLLOW : 0)) {
+ warn("utimensat: %s", to.p_path);
rval = 1;
}
if (fdval ? fstat(fd, &ts) :
OpenPOWER on IntegriCloud