File: timeval.c

package info (click to toggle)
superkb 0.23-5
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 492 kB
  • sloc: ansic: 3,915; sh: 187; makefile: 182
file content (42 lines) | stat: -rw-r--r-- 764 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
/*
 * timeval.c
 *
 * Copyright (C) 2006, Octavio Alvarez Piza.
 * License: GNU General Public License v2.
 *
 */

/* timeval.c: This provides with some timeval functions if not provided
 *            by the system.
 */

#include "timeval.h"

#ifndef _GNU_SOURCE

void
timersub(struct timeval *a, struct timeval *b, struct timeval *res)
{
	if (a->tv_usec >= b->tv_usec) {
		res->tv_usec = a->tv_usec - b->tv_usec;
		res->tv_sec = a->tv_sec - b->tv_sec;
	} else {
		res->tv_usec = a->tv_usec - b->tv_usec + 1000000;
		res->tv_sec = a->tv_sec - b->tv_sec - 1;
	}
}

int
timerisset(struct timeval *tv)
{
	return ((tv->tv_sec != 0) || (tv->tv_usec != 0));
}

void
timerclear(struct timeval *tv)
{
	tv->tv_sec = 0;
	tv->tv_usec = 0;
}

#endif /* #ifndef _GNU_SOURCE */