From 741c1ef7a4f2ac316ad6e557ddbe03023413478d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 04:22:06 +0200 Subject: Adding upstream version 1:4.5. Signed-off-by: Daniel Baumann --- tests/common/time_past.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/common/time_past.c (limited to 'tests/common/time_past.c') diff --git a/tests/common/time_past.c b/tests/common/time_past.c new file mode 100644 index 0000000..d0eb741 --- /dev/null +++ b/tests/common/time_past.c @@ -0,0 +1,52 @@ +/* + * gcc time_past.c -o time_past.so -shared -ldl + * LD_PRELOAD=./time_past.so PAST_DAYS=2 ./test + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +typedef time_t (*time_type) (time_t *t); +static time_type next_time; + +static int time_past = 0; +static char *past = NULL; + +time_t time (time_t *t) +{ + time_t res; + + if (NULL == next_time) + { + next_time = dlsym (RTLD_NEXT, "time"); + assert (NULL != next_time); + } + if (NULL == past) { + const char *past = getenv ("PAST_DAYS"); + if (NULL == past) { + fputs ("No PAST_DAYS defined\n", stderr); + } + time_past = atoi (past); + } + + res = next_time (t); + res -= 24*60*60*time_past; + + if (NULL != t) { + *t = res; + } + + return res; +} + -- cgit v1.2.3