summaryrefslogtreecommitdiffstats
path: root/regress/sys/kern/gettimeofday/gettimeofday.c
blob: df6771a3b83299f2e5a239e6c9a3d675679940be (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
27
28
29
30
31
/*	$OpenBSD: gettimeofday.c,v 1.2 2003/07/31 21:48:08 deraadt Exp $	*/
/*
 *	Written by Thomas Nordin <nordin@openbsd.org> 2002 Public Domain.
 */
#include <err.h>
#include <stdio.h>

#include <sys/time.h>

int
main(int argc, char *argv[])
{
	struct timeval s;
	struct timeval t1;
	struct timeval t2;

	if (gettimeofday(&s, NULL) == -1)
		err(1, "gettimeofday");

	do {
		if (gettimeofday(&t1, NULL) == -1)
			err(1, "gettimeofday");
		if (gettimeofday(&t2, NULL) == -1)
			err(1, "gettimeofday");

		if (timercmp(&t2, &t1, <))
			errx(1, "time of day decreased");
        } while (t1.tv_sec - s.tv_sec < 7);

        return 0;
}