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