From 6541b77c94127ecd11c0a5f7b2cdfe2db3a4a356 Mon Sep 17 00:00:00 2001 From: guenther Date: Fri, 11 Aug 2023 05:02:21 +0000 Subject: [PATCH] Switch rcs_{get,set}_mtime() from returning and taking a time_t to doing so with a struct timespec and then use tv_nsec = UTIME_OMIT instead of a (time_t)-1 as a "do nothing" value. They can then fully preserve the timestamp ok millert@ --- usr.bin/rcs/co.c | 4 ++-- usr.bin/rcs/rcsclean.c | 5 +++-- usr.bin/rcs/rcsprog.c | 4 ++-- usr.bin/rcs/rcsutil.c | 30 ++++++++++++++---------------- usr.bin/rcs/rcsutil.h | 6 +++--- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c index 97baae78c44..c13b30aa205 100644 --- a/usr.bin/rcs/co.c +++ b/usr.bin/rcs/co.c @@ -1,4 +1,4 @@ -/* $OpenBSD: co.c,v 1.126 2019/06/28 13:35:03 deraadt Exp $ */ +/* $OpenBSD: co.c,v 1.127 2023/08/11 05:02:21 guenther Exp $ */ /* * Copyright (c) 2005 Joris Vink * All rights reserved. @@ -52,7 +52,7 @@ checkout_main(int argc, char **argv) const char *author, *date, *state; char fpath[PATH_MAX]; char *rev_str, *username; - time_t rcs_mtime = -1; + struct timespec rcs_mtime = { .tv_sec = 0, .tv_nsec = UTIME_OMIT }; flags = ret = 0; kflag = RCS_KWEXP_ERR; diff --git a/usr.bin/rcs/rcsclean.c b/usr.bin/rcs/rcsclean.c index 2b48bc06f5b..8c4d71a1dde 100644 --- a/usr.bin/rcs/rcsclean.c +++ b/usr.bin/rcs/rcsclean.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsclean.c,v 1.56 2016/08/26 09:02:54 guenther Exp $ */ +/* $OpenBSD: rcsclean.c,v 1.57 2023/08/11 05:02:21 guenther Exp $ */ /* * Copyright (c) 2005 Joris Vink * All rights reserved. @@ -25,6 +25,7 @@ */ #include +#include #include #include @@ -137,7 +138,7 @@ rcsclean_file(char *fname, const char *rev_str) char fpath[PATH_MAX], numb[RCS_REV_BUFSZ]; RCSNUM *rev; BUF *b1, *b2; - time_t rcs_mtime = -1; + struct timespec rcs_mtime = { .tv_sec = 0, .tv_nsec = UTIME_OMIT }; b1 = b2 = NULL; file = NULL; diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index f68b3f1b694..66925925313 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.164 2023/03/08 04:43:12 guenther Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.165 2023/08/11 05:02:21 guenther Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau * All rights reserved. @@ -191,7 +191,7 @@ rcs_main(int argc, char **argv) RCSFILE *file; RCSNUM *logrev; struct rcs_access *acp; - time_t rcs_mtime = -1; + struct timespec rcs_mtime = { .tv_sec = 0, .tv_nsec = UTIME_OMIT }; kflag = RCS_KWEXP_ERR; lkmode = RCS_LOCK_INVAL; diff --git a/usr.bin/rcs/rcsutil.c b/usr.bin/rcs/rcsutil.c index c423b220bff..875434e2c47 100644 --- a/usr.bin/rcs/rcsutil.c +++ b/usr.bin/rcs/rcsutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsutil.c,v 1.47 2020/10/14 20:07:19 naddy Exp $ */ +/* $OpenBSD: rcsutil.c,v 1.48 2023/08/11 05:02:21 guenther Exp $ */ /* * Copyright (c) 2005, 2006 Joris Vink * Copyright (c) 2006 Xavier Santolaria @@ -44,44 +44,42 @@ * rcs_get_mtime() * * Get last modified time. - * Returns last modified time on success, or -1 on failure. + * Returns last modified time on success, or a timespec with tv_nsec + * set to UTIME_OMIT on failure. */ -time_t +struct timespec rcs_get_mtime(RCSFILE *file) { struct stat st; - time_t mtime; + struct timespec mtime = { .tv_sec = 0, .tv_nsec = UTIME_OMIT }; if (file->rf_file == NULL) - return (-1); + return mtime; if (fstat(fileno(file->rf_file), &st) == -1) { warn("%s", file->rf_path); - return (-1); + return mtime; } - mtime = st.st_mtimespec.tv_sec; - - return (mtime); + return st.st_mtim; } /* * rcs_set_mtime() * - * Set last modified time to if it's not set to -1. + * Set last modified time to if its tv_nsec isn't UTIME_OMIT */ void -rcs_set_mtime(RCSFILE *file, time_t mtime) +rcs_set_mtime(RCSFILE *file, struct timespec mtime) { - static struct timeval tv[2]; + struct timespec ts[2]; - if (file->rf_file == NULL || mtime == -1) + if (file->rf_file == NULL || mtime.tv_nsec == UTIME_OMIT) return; - tv[0].tv_sec = mtime; - tv[1].tv_sec = tv[0].tv_sec; + ts[0] = ts[1] = mtime; - if (futimes(fileno(file->rf_file), tv) == -1) + if (futimens(fileno(file->rf_file), ts) == -1) err(1, "utimes"); } diff --git a/usr.bin/rcs/rcsutil.h b/usr.bin/rcs/rcsutil.h index cb046efcf3c..a919da4e70a 100644 --- a/usr.bin/rcs/rcsutil.h +++ b/usr.bin/rcs/rcsutil.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsutil.h,v 1.15 2016/07/04 01:39:12 millert Exp $ */ +/* $OpenBSD: rcsutil.h,v 1.16 2023/08/11 05:02:21 guenther Exp $ */ /* * Copyright (c) 2006 Xavier Santolaria * All rights reserved. @@ -50,9 +50,9 @@ struct rcs_argvector { /* rcsutil.c */ int rcs_getopt(int, char **, const char *); -void rcs_set_mtime(RCSFILE *, time_t); +void rcs_set_mtime(RCSFILE *, struct timespec); int rcs_choosefile(const char *, char *, size_t); -time_t rcs_get_mtime(RCSFILE *); +struct timespec rcs_get_mtime(RCSFILE *); RCSNUM *rcs_getrevnum(const char *, RCSFILE *); char *rcs_prompt(const char *, int); u_int rcs_rev_select(RCSFILE *, const char *); -- 2.20.1