[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] test_util.c: Extract utime() function.
commit f3e5b283ad0c589acf4eda31d7ca478553c28376
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Jul 30 10:37:45 2020 -0400
test_util.c: Extract utime() function.
We need this to manipulate mtimes, but only in this file.
---
src/test/test_util.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 2aee07a26a..5fe9617f89 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -77,6 +77,8 @@
#define DISABLE_PWDB_TESTS
#endif
+static void set_file_mtime(const char *fname, time_t when);
+
#define INFINITY_DBL ((double)INFINITY)
#define NAN_DBL ((double)NAN)
@@ -5786,6 +5788,20 @@ test_util_get_avail_disk_space(void *arg)
;
}
+/** Helper: Change the atime and mtime of a file. */
+static void
+set_file_mtime(const char *fname, time_t when)
+{
+ struct utimbuf u = { when, when };
+ struct stat st;
+ tt_int_op(0, OP_EQ, utime(fname, &u));
+ tt_int_op(0, OP_EQ, stat(fname, &st));
+ /* Let's hope that utime/stat give the same second as a round-trip? */
+ tt_i64_op(st.st_mtime, OP_EQ, when);
+done:
+ ;
+}
+
static void
test_util_touch_file(void *arg)
{
@@ -5803,11 +5819,7 @@ test_util_touch_file(void *arg)
tt_i64_op(st.st_mtime, OP_GE, now - 1);
const time_t five_sec_ago = now - 5;
- struct utimbuf u = { five_sec_ago, five_sec_ago };
- tt_int_op(0, OP_EQ, utime(fname, &u));
- tt_int_op(0, OP_EQ, stat(fname, &st));
- /* Let's hope that utime/stat give the same second as a round-trip? */
- tt_i64_op(st.st_mtime, OP_EQ, five_sec_ago);
+ set_file_mtime(fname, five_sec_ago);
/* Finally we can touch the file */
tt_int_op(0, OP_EQ, touch_file(fname));
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits