]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/internal/man3/OSSL_TIME.pod
Make OSSL_TIME a structure
[thirdparty/openssl.git] / doc / internal / man3 / OSSL_TIME.pod
CommitLineData
9f40251d
P
1=pod
2
3=head1 NAME
4
d13c8b77
P
5OSSL_TIME, OSSL_TIME_SECOND, ossl_time_infinite, ossl_time_zero,
6ossl_ticks2time, ossl_time2ticks,
9f40251d
P
7ossl_time_now, ossl_time_time_to_timeval, ossl_time_compare,
8ossl_time_add, ossl_time_subtract
9- times and durations
10
11=head1 SYNOPSIS
12
13 #include "internal/time.h"
14
d13c8b77 15 typedef struct OSSL_TIME;
9f40251d 16
d13c8b77 17 #define OSSL_TIME_SECOND /* Ticks per second */
9f40251d 18
d13c8b77
P
19 OSSL_TIME ossl_ticks2time(uint64_t);
20 uint64_t ossl_time2ticks(OSSL_TIME t);
21
22 OSSL_TIME ossl_time_zero(void);
23 OSSL_TIME ossl_time_infinite(void);
9f40251d 24 OSSL_TIME ossl_time_now(void);
d13c8b77 25
9f40251d
P
26 void ossl_time_time_to_timeval(OSSL_TIME t, struct timeval *out);
27
28 int ossl_time_compare(OSSL_TIME a, OSSL_TIME b);
29 OSSL_TIME ossl_time_add(OSSL_TIME a, OSSL_TIME b);
30 OSSL_TIME ossl_time_subtract(OSSL_TIME a, OSSL_TIME b);
31
32=head1 DESCRIPTION
33
34These functions allow the current time to be obtained and for basic
35arithmetic operations to be safely performed with times and durations.
36
37B<OSSL_TIME> can represent a duration, or a point in time. Where it is
38used to represent a point in time, it does so by expressing a duration
39relative to some reference Epoch. The OSSL_TIME structure itself does
40not contain information about the Epoch used; thus, interpretation of
41an OSSL_TIME requires that the Epoch it is to be interpreted relative
42to is contextually understood.
43
44B<OSSL_TIME_SECOND> is an integer that indicates the precision of an
45B<OSSL_TIME>. Specifically, it is the number of counts per second that
46a time can represent. The accuracy is independent of this and is system
47dependent.
48
d13c8b77
P
49B<ossl_ticks2time> converts an integral number of counts to a time.
50
51B<ossl_time2ticks> converts a time to an integral number of counts.
52
53B<ossl_time_zero> returns the smallest representable B<OSSL_TIME>.
54This value represents the time Epoch and it is returned when an underflow
55would otherwise occur.
56
57B<ossl_time_infinite> returns the largest representable B<OSSL_TIME>.
58This value is returned when an overflow would otherwise occur.
9f40251d
P
59
60B<ossl_time_now> returns the current time relative to an Epoch which
61is undefined but unchanging for at least the duration of program
62execution. The time returned is monotonic and need not represent
63wall-clock time. The time returned by this function is useful for
64scheduling timeouts, deadlines and recurring events, but due to its
65undefined Epoch and monotonic nature, is not suitable for other uses.
66
67B<ossl_time_time_to_timeval> converts a time to a I<struct timeval>.
68
69B<ossl_time_compare> compares I<a> with I<b> and returns -1 if I<a>
70is smaller than I<b>, 0 if they are equal and +1 if I<a> is
71larger than I<b>.
72
73B<ossl_time_add> performs a saturating addition of the two times,
74returning I<a> + I<b>.
75If the summation would overflow B<OSSL_TIME_INFINITY> is returned.
76
77B<ossl_time_subtract> performs a saturating subtraction of the two items,
78returning I<a> - I<b>.
79If the difference would be negative, B<0> is returned.
80
81=head1 NOTES
82
83The largest representable duration is guaranteed to be at least 500 years.
84
85=head1 RETURN VALUES
86
d13c8b77
P
87B<ossl_time_now> returns the current time, or the time of the Epoch on error.
88
89B<ossl_time_zero> returns the time of the Epoch.
90
91B<ossl_time_infinite> returns the last representable time.
92
93B<ossl_ticks2time> return the duration specified.
94
95B<ossl_time2ticks> returns the ticks since Epoch.
9f40251d
P
96
97B<ossl_time_compare> returns -1, 0 or 1 depending on the comparison.
98
99B<ossl_time_add> returns the summation of the two times or
d13c8b77 100the last representable time on overflow.
9f40251d
P
101
102B<ossl_time_subtract> returns the difference of the two times or the
d13c8b77 103time of the Epoch on underflow.
9f40251d
P
104
105=head1 HISTORY
106
107This functionality was added in OpenSSL 3.1.
108
109=head1 COPYRIGHT
110
111Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
112
113Licensed under the Apache License 2.0 (the "License"). You may not use this
114file except in compliance with the License. You can obtain a copy in the file
115LICENSE in the source distribution or at
116L<https://www.openssl.org/source/license.html>.
117
118=cut