summaryrefslogtreecommitdiffstats
path: root/tests/helpers/libpreload-time.c
blob: e69795098e7784880c0d81d767a06313eff25c5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

time_t
time(time_t *t)
{
	time_t tt = 0;
	char *e = getenv("TEST_TIME");

	if (e && isdigit((unsigned char) *e))
		tt = atol(e);
	else {
		struct timeval tv;

		if (gettimeofday(&tv, NULL) == 0)
			tt = tv.tv_sec;
	}
	if (t)
		*t = tt;

	return tt;
}