time.h 3.05 KB
Newer Older
Bob Halley's avatar
add    
Bob Halley committed
1

Bob Halley's avatar
Bob Halley committed
2
3
4
#ifndef ISC_TIME_H
#define ISC_TIME_H 1

Bob Halley's avatar
add    
Bob Halley committed
5
#include <isc/result.h>
6
#include <isc/boolean.h>
Bob Halley's avatar
add    
Bob Halley committed
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/***
 *** Intervals
 ***/

/*
 * The contents of this structure are private, and MUST NOT be accessed
 * directly by callers.
 *
 * The contents are exposed only so that callers may avoid dynamic allocation
 * and instead just declare a 'struct isc_interval'.
 */
typedef struct isc_interval {
	unsigned int seconds;
	unsigned int nanoseconds;
} *isc_interval_t;

void
isc_interval_set(isc_interval_t i,
		 unsigned int seconds, unsigned int nanoseconds);
/*
 * Set 'i' to a value representing an interval of 'seconds' seconds and
 * 'nanoseconds' nanoseconds, suitable for use in isc_time_add() and
 * isc_time_subtract().
 *
 * Requires:
 *
 *	't' is a valid.
 *
 *	nanoseconds < 1000000000
 */

isc_boolean_t
isc_interval_iszero(isc_interval_t i);
/*
 * Returns ISC_TRUE iff. 'i' is the zero interval.
 *
 * Requires:
 *
 *	't' is a valid.
 *
 */

/***
 *** Absolute Times
 ***/

/*
 * The contents of this structure are private, and MUST NOT be accessed
 * directly by callers.
 *
 * The contents are exposed only so that callers may avoid dynamic allocation
 * and instead just declare a 'struct isc_time'.
Bob Halley's avatar
add    
Bob Halley committed
60
61
 */

Bob Halley's avatar
Bob Halley committed
62
typedef struct isc_time {
63
64
	time_t		seconds;
	unsigned int	nanoseconds;
Bob Halley's avatar
Bob Halley committed
65
} *isc_time_t;
Bob Halley's avatar
add    
Bob Halley committed
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
void
isc_time_settoepoch(isc_time_t t);
/*
 * Set 't' to the time of the epoch.
 *
 * Requires:
 *
 *	't' is a valid.
 *
 */

isc_boolean_t
isc_time_isepoch(isc_time_t t);
/*
 * Returns ISC_TRUE iff. 't' is the epoch ("time zero").
 *
 * Requires:
 *
 *	't' is a valid.
 *
 */

Bob Halley's avatar
Bob Halley committed
89
90
isc_result_t
isc_time_get(isc_time_t t);
Bob Halley's avatar
add    
Bob Halley committed
91
/*
92
 * Set 't' to the current absolute time.
Bob Halley's avatar
add    
Bob Halley committed
93
94
95
 *
 * Requires:
 *
Bob Halley's avatar
Bob Halley committed
96
 *	't' is a valid pointer.
Bob Halley's avatar
add    
Bob Halley committed
97
98
99
100
101
102
103
104
 *
 * Returns:
 *
 *	Success
 *	Unexpected error
 */

int
Bob Halley's avatar
Bob Halley committed
105
isc_time_compare(isc_time_t t1, isc_time_t t2);
Bob Halley's avatar
add    
Bob Halley committed
106
/*
Bob Halley's avatar
Bob Halley committed
107
 * Compare the times referenced by 't1' and 't2'
Bob Halley's avatar
add    
Bob Halley committed
108
109
110
 *
 * Requires:
 *
Bob Halley's avatar
Bob Halley committed
111
 *	't1' and 't2' are a valid.
Bob Halley's avatar
add    
Bob Halley committed
112
113
114
 *
 * Returns:
 *
Bob Halley's avatar
Bob Halley committed
115
116
117
 *	-1		t1 < t2		(comparing times, not pointers)
 *	0		t1 = t2
 *	1		t1 > t2
Bob Halley's avatar
add    
Bob Halley committed
118
119
120
 */

void
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
isc_time_add(isc_time_t t, isc_interval_t i, isc_time_t result);
/*
 * Add 'i' to 't', storing the result in 'result'.
 *
 * Requires:
 *
 *	't', 'i', and 'result' are valid.
 */

void
isc_time_subtract(isc_time_t t, isc_interval_t t2, isc_time_t result);
/*
 * Subtract 'i' from 't', storing the result in 'result'.
 *
 * Requires:
 *
 *	't', 'i', and 'result' are valid.
 *
 *	t >= epoch + i			(comparing times, not pointers)
 */

/***
 *** UNIX-only
 ***/

void
isc_time_fromtimeval(isc_time_t t, struct timeval *tv);
Bob Halley's avatar
add    
Bob Halley committed
148
/*
149
 * Set 't' to the time given by 'ts'.
Bob Halley's avatar
add    
Bob Halley committed
150
151
152
 *
 * Requires:
 *
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 *	't' and 'tv' are a valid.
 *
 */

void
isc_time_totimeval(isc_time_t t, struct timeval *tv);
/*
 * Convert 't' to a UNIX timeval.
 *
 * Requires:
 *
 *	't' and 'tv' are a valid.
 *
 */

void
isc_time_fromtimespec(isc_time_t t, struct timespec *ts);
/*
 * Set 't' to the time given by 'ts'.
 *
 * Requires:
 *
 *	't' and 'ts' are a valid.
 *
Bob Halley's avatar
add    
Bob Halley committed
177
178
179
 */

void
180
isc_time_totimespec(isc_time_t t, struct timespec *ts);
Bob Halley's avatar
add    
Bob Halley committed
181
/*
182
 * Convert 't' to a UNIX timespec.
Bob Halley's avatar
add    
Bob Halley committed
183
184
185
 *
 * Requires:
 *
186
 *	't' and 'ts' are a valid.
Bob Halley's avatar
add    
Bob Halley committed
187
188
 *
 */
Bob Halley's avatar
Bob Halley committed
189
190

#endif /* ISC_TIME_H */