summaryrefslogtreecommitdiff
path: root/regress/sys/kern/gettimeofday/gettimeofday.c
blob: b27d16f9c0a1e91eb7e360b3576b3c1ee4b48a7d (plain)
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.1 2002/02/21 09:21:30 nordin Exp $	*/
/*
 *	Written by Thomas Nordin <nordin@openbsd.org> 2002 Public Domain.
 */
#include <err.h>
#include <stdio.h>

#include <sys/time.h>

int
main()
{
	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;
}