jcs's openbsd hax
openbsd

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@

guenther ea7ffa33 6541b77c

+18 -19
+10 -11
usr.sbin/mtree/compare.c
··· 1 1 /* $NetBSD: compare.c,v 1.11 1996/09/05 09:56:48 mycroft Exp $ */ 2 - /* $OpenBSD: compare.c,v 1.29 2021/10/24 21:24:19 deraadt Exp $ */ 2 + /* $OpenBSD: compare.c,v 1.30 2023/08/11 05:07:28 guenther Exp $ */ 3 3 4 4 /*- 5 5 * Copyright (c) 1989, 1993 ··· 196 196 * Doesn't display microsecond differences. 197 197 */ 198 198 if (s->flags & F_TIME) { 199 - struct timeval tv[2]; 199 + struct timespec ts[2]; 200 200 201 - TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); 202 - TIMESPEC_TO_TIMEVAL(&tv[1], &p->fts_statp->st_mtimespec); 203 - if (tv[0].tv_sec != tv[1].tv_sec || 204 - tv[0].tv_usec != tv[1].tv_usec) { 201 + ts[0] = s->st_mtim; 202 + ts[1] = p->fts_statp->st_mtim; 203 + if (ts[0].tv_sec != ts[1].tv_sec || 204 + ts[0].tv_nsec != ts[1].tv_nsec) { 205 205 LABEL; 206 206 (void)printf("%smodification time (%.24s, ", 207 - tab, ctime(&s->st_mtimespec.tv_sec)); 208 - (void)printf("%.24s", 209 - ctime(&p->fts_statp->st_mtimespec.tv_sec)); 207 + tab, ctime(&s->st_mtime)); 208 + (void)printf("%.24s", ctime(&p->fts_statp->st_mtime)); 210 209 if (tflag) { 211 - tv[1] = tv[0]; 212 - if (utimes(p->fts_accpath, tv)) 210 + ts[1] = ts[0]; 211 + if (utimensat(AT_FDCWD, p->fts_accpath, ts, 0)) 213 212 (void)printf(", not modified: %s)\n", 214 213 strerror(errno)); 215 214 else
+3 -3
usr.sbin/mtree/create.c
··· 1 1 /* $NetBSD: create.c,v 1.11 1996/09/05 09:24:19 mycroft Exp $ */ 2 - /* $OpenBSD: create.c,v 1.35 2021/10/24 21:24:19 deraadt Exp $ */ 2 + /* $OpenBSD: create.c,v 1.36 2023/08/11 05:07:28 guenther Exp $ */ 3 3 4 4 /*- 5 5 * Copyright (c) 1989, 1993 ··· 189 189 (long long)p->fts_statp->st_size); 190 190 if (keys & F_TIME) 191 191 output(indent, &offset, "time=%lld.%ld", 192 - (long long)p->fts_statp->st_mtimespec.tv_sec, 193 - p->fts_statp->st_mtimespec.tv_nsec); 192 + (long long)p->fts_statp->st_mtim.tv_sec, 193 + p->fts_statp->st_mtim.tv_nsec); 194 194 if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { 195 195 if ((fd = open(p->fts_accpath, MTREE_O_FLAGS)) == -1 || 196 196 crc(fd, &val, &len))
+2 -2
usr.sbin/mtree/mtree.h
··· 1 - /* $OpenBSD: mtree.h,v 1.13 2012/07/08 21:19:42 naddy Exp $ */ 1 + /* $OpenBSD: mtree.h,v 1.14 2023/08/11 05:07:28 guenther Exp $ */ 2 2 /* $NetBSD: mtree.h,v 1.7 1995/03/07 21:26:27 cgd Exp $ */ 3 3 4 4 /*- ··· 48 48 struct _node *parent, *child; /* up, down */ 49 49 struct _node *prev, *next; /* left, right */ 50 50 off_t st_size; /* size */ 51 - struct timespec st_mtimespec; /* last modification time */ 51 + struct timespec st_mtim; /* last modification time */ 52 52 u_int32_t cksum; /* check sum */ 53 53 char *md5digest; /* MD5 digest */ 54 54 char *rmd160digest; /* RIPEMD-160 digest */
+3 -3
usr.sbin/mtree/spec.c
··· 1 1 /* $NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $ */ 2 - /* $OpenBSD: spec.c,v 1.29 2018/09/16 02:41:16 millert Exp $ */ 2 + /* $OpenBSD: spec.c,v 1.30 2023/08/11 05:07:28 guenther Exp $ */ 3 3 4 4 /*- 5 5 * Copyright (c) 1989, 1993 ··· 253 253 } 254 254 break; 255 255 case F_TIME: 256 - ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10); 256 + ip->st_mtim.tv_sec = strtoull(val, &ep, 10); 257 257 if (*ep != '.') 258 258 error("invalid time %s", val); 259 259 val = ep + 1; 260 - ip->st_mtimespec.tv_nsec = strtoul(val, &ep, 10); 260 + ip->st_mtim.tv_nsec = strtoul(val, &ep, 10); 261 261 if (*ep) 262 262 error("invalid time %s", val); 263 263 break;