xref: /openbsd-src/lib/libcrypto/asn1/posix_time.h (revision f21279a16d6bd54f2e4c617a28077aea6954f74e)
1*f21279a1Stb /*	$OpenBSD: posix_time.h,v 1.1 2024/02/18 16:28:38 tb Exp $ */
2*f21279a1Stb /*
3*f21279a1Stb  * Copyright (c) 2022, Google Inc.
4*f21279a1Stb  *
5*f21279a1Stb  * Permission to use, copy, modify, and/or distribute this software for any
6*f21279a1Stb  * purpose with or without fee is hereby granted, provided that the above
7*f21279a1Stb  * copyright notice and this permission notice appear in all copies.
8*f21279a1Stb  *
9*f21279a1Stb  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*f21279a1Stb  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*f21279a1Stb  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12*f21279a1Stb  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*f21279a1Stb  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14*f21279a1Stb  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15*f21279a1Stb  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*f21279a1Stb  */
17*f21279a1Stb 
18*f21279a1Stb #ifndef OPENSSL_HEADER_POSIX_TIME_H
19*f21279a1Stb #define OPENSSL_HEADER_POSIX_TIME_H
20*f21279a1Stb 
21*f21279a1Stb #include <stdint.h>
22*f21279a1Stb #include <time.h>
23*f21279a1Stb 
24*f21279a1Stb #if defined(__cplusplus)
25*f21279a1Stb extern "C" {
26*f21279a1Stb #endif
27*f21279a1Stb 
28*f21279a1Stb /*
29*f21279a1Stb  * OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time|, which must
30*f21279a1Stb  * be in the range of year 0000 to 9999, to a broken out time value in |tm|. It
31*f21279a1Stb  * returns one on success and zero on error.
32*f21279a1Stb  */
33*f21279a1Stb int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm);
34*f21279a1Stb 
35*f21279a1Stb /*
36*f21279a1Stb  * OPENSSL_tm_to_posix converts a time value between the years 0 and 9999 in
37*f21279a1Stb  * |tm| to a POSIX time value in |out|. One is returned on success, zero is
38*f21279a1Stb  * returned on failure. It is a failure if |tm| contains out of range values.
39*f21279a1Stb  */
40*f21279a1Stb int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out);
41*f21279a1Stb 
42*f21279a1Stb /*
43*f21279a1Stb  * OPENSSL_timegm converts a time value between the years 0 and 9999 in |tm| to
44*f21279a1Stb  * a time_t value in |out|. One is returned on success, zero is returned on
45*f21279a1Stb  * failure. It is a failure if the converted time can not be represented in a
46*f21279a1Stb  * time_t, or if the tm contains out of range values.
47*f21279a1Stb  */
48*f21279a1Stb int OPENSSL_timegm(const struct tm *tm, time_t *out);
49*f21279a1Stb 
50*f21279a1Stb #if defined(__cplusplus)
51*f21279a1Stb }  /* extern C */
52*f21279a1Stb #endif
53*f21279a1Stb 
54*f21279a1Stb #endif  /* OPENSSL_HEADER_POSIX_TIME_H */
55