From ea7ffa33202d03451f764fa91a44405dec2d2d30 Mon Sep 17 00:00:00 2001 From: guenther Date: Fri, 11 Aug 2023 05:07:28 +0000 Subject: [PATCH] Stop down-converting to a timeval when comparing and setting times. Replace use of the old BSD st_*timespec members in struct stat with the POSIX-standard st_*tim members. ok millert@ --- usr.sbin/mtree/compare.c | 21 ++++++++++----------- usr.sbin/mtree/create.c | 6 +++--- usr.sbin/mtree/mtree.h | 4 ++-- usr.sbin/mtree/spec.c | 6 +++--- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index 8ba1cd505a9..6ac3ff76508 100644 --- a/usr.sbin/mtree/compare.c +++ b/usr.sbin/mtree/compare.c @@ -1,5 +1,5 @@ /* $NetBSD: compare.c,v 1.11 1996/09/05 09:56:48 mycroft Exp $ */ -/* $OpenBSD: compare.c,v 1.29 2021/10/24 21:24:19 deraadt Exp $ */ +/* $OpenBSD: compare.c,v 1.30 2023/08/11 05:07:28 guenther Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -196,20 +196,19 @@ typeerr: LABEL; * Doesn't display microsecond differences. */ if (s->flags & F_TIME) { - struct timeval tv[2]; + struct timespec ts[2]; - TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); - TIMESPEC_TO_TIMEVAL(&tv[1], &p->fts_statp->st_mtimespec); - if (tv[0].tv_sec != tv[1].tv_sec || - tv[0].tv_usec != tv[1].tv_usec) { + ts[0] = s->st_mtim; + ts[1] = p->fts_statp->st_mtim; + if (ts[0].tv_sec != ts[1].tv_sec || + ts[0].tv_nsec != ts[1].tv_nsec) { LABEL; (void)printf("%smodification time (%.24s, ", - tab, ctime(&s->st_mtimespec.tv_sec)); - (void)printf("%.24s", - ctime(&p->fts_statp->st_mtimespec.tv_sec)); + tab, ctime(&s->st_mtime)); + (void)printf("%.24s", ctime(&p->fts_statp->st_mtime)); if (tflag) { - tv[1] = tv[0]; - if (utimes(p->fts_accpath, tv)) + ts[1] = ts[0]; + if (utimensat(AT_FDCWD, p->fts_accpath, ts, 0)) (void)printf(", not modified: %s)\n", strerror(errno)); else diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c index d5cbd6b0a6c..dc051e65d60 100644 --- a/usr.sbin/mtree/create.c +++ b/usr.sbin/mtree/create.c @@ -1,5 +1,5 @@ /* $NetBSD: create.c,v 1.11 1996/09/05 09:24:19 mycroft Exp $ */ -/* $OpenBSD: create.c,v 1.35 2021/10/24 21:24:19 deraadt Exp $ */ +/* $OpenBSD: create.c,v 1.36 2023/08/11 05:07:28 guenther Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -189,8 +189,8 @@ statf(int indent, FTSENT *p) (long long)p->fts_statp->st_size); if (keys & F_TIME) output(indent, &offset, "time=%lld.%ld", - (long long)p->fts_statp->st_mtimespec.tv_sec, - p->fts_statp->st_mtimespec.tv_nsec); + (long long)p->fts_statp->st_mtim.tv_sec, + p->fts_statp->st_mtim.tv_nsec); if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, MTREE_O_FLAGS)) == -1 || crc(fd, &val, &len)) diff --git a/usr.sbin/mtree/mtree.h b/usr.sbin/mtree/mtree.h index 55e1702aff9..2957d30876d 100644 --- a/usr.sbin/mtree/mtree.h +++ b/usr.sbin/mtree/mtree.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mtree.h,v 1.13 2012/07/08 21:19:42 naddy Exp $ */ +/* $OpenBSD: mtree.h,v 1.14 2023/08/11 05:07:28 guenther Exp $ */ /* $NetBSD: mtree.h,v 1.7 1995/03/07 21:26:27 cgd Exp $ */ /*- @@ -48,7 +48,7 @@ typedef struct _node { struct _node *parent, *child; /* up, down */ struct _node *prev, *next; /* left, right */ off_t st_size; /* size */ - struct timespec st_mtimespec; /* last modification time */ + struct timespec st_mtim; /* last modification time */ u_int32_t cksum; /* check sum */ char *md5digest; /* MD5 digest */ char *rmd160digest; /* RIPEMD-160 digest */ diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 34864b0a541..88af6a05074 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -1,5 +1,5 @@ /* $NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $ */ -/* $OpenBSD: spec.c,v 1.29 2018/09/16 02:41:16 millert Exp $ */ +/* $OpenBSD: spec.c,v 1.30 2023/08/11 05:07:28 guenther Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -253,11 +253,11 @@ set(char *t, NODE *ip) } break; case F_TIME: - ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10); + ip->st_mtim.tv_sec = strtoull(val, &ep, 10); if (*ep != '.') error("invalid time %s", val); val = ep + 1; - ip->st_mtimespec.tv_nsec = strtoul(val, &ep, 10); + ip->st_mtim.tv_nsec = strtoul(val, &ep, 10); if (*ep) error("invalid time %s", val); break; -- 2.20.1