diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2023-08-11 05:02:22 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2023-08-11 05:02:22 +0000 |
commit | 95ba6c108d285aada738a4a831e420f6db9cbd54 (patch) | |
tree | 018d47274c4ef56515df4d4ddb3d2f426aa06d67 | |
parent | 08bef46fb105b9c6aecabbe017b56c9d09a9a45f (diff) |
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@
-rw-r--r-- | usr.bin/rcs/co.c | 4 | ||||
-rw-r--r-- | usr.bin/rcs/rcsclean.c | 5 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 4 | ||||
-rw-r--r-- | usr.bin/rcs/rcsutil.c | 30 | ||||
-rw-r--r-- | 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 <joris@openbsd.org> * 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 <joris@openbsd.org> * All rights reserved. @@ -25,6 +25,7 @@ */ #include <sys/types.h> +#include <sys/stat.h> #include <dirent.h> #include <err.h> @@ -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 <jfb@openbsd.org> * 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 <joris@openbsd.org> * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> @@ -44,44 +44,42 @@ * rcs_get_mtime() * * Get <filename> 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 <filename> last modified time to <mtime> if it's not set to -1. + * Set <filename> last modified time to <mtime> 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 <xsa@openbsd.org> * 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 *); |