File: testgettimeofday.c

package info (click to toggle)
hf 0.7.3-4etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,684 kB
  • ctags: 3,156
  • sloc: ansic: 26,447; cpp: 4,909; sh: 3,785; makefile: 309
file content (25 lines) | stat: -rw-r--r-- 518 bytes parent folder | download | duplicates (4)
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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

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

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

	if (gettimeofday(&t1, NULL)) {
		perror("gettimeofday");
		exit(1);
	}
	if (gettimeofday(&t2, NULL)) {
		perror("gettimeofday");
		exit(1);
	}
	printf("time0: %lu  time1: %lu  diff: %lu\n", (unsigned long)t1.tv_usec,
	       (unsigned long)t2.tv_usec, (unsigned long)((1000000+t2.tv_usec-t1.tv_usec) % 1000000));
	exit(0);
}