posix_time.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef OPENSSL_HEADER_POSIX_TIME_H
  18. #define OPENSSL_HEADER_POSIX_TIME_H
  19. #include <stdint.h>
  20. #include <time.h>
  21. #if defined(__cplusplus)
  22. extern "C" {
  23. #endif
  24. /*
  25. * OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time|, which must
  26. * be in the range of year 0000 to 9999, to a broken out time value in |tm|. It
  27. * returns one on success and zero on error.
  28. */
  29. int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm);
  30. /*
  31. * OPENSSL_tm_to_posix converts a time value between the years 0 and 9999 in
  32. * |tm| to a POSIX time value in |out|. One is returned on success, zero is
  33. * returned on failure. It is a failure if |tm| contains out of range values.
  34. */
  35. int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out);
  36. /*
  37. * OPENSSL_timegm converts a time value between the years 0 and 9999 in |tm| to
  38. * a time_t value in |out|. One is returned on success, zero is returned on
  39. * failure. It is a failure if the converted time can not be represented in a
  40. * time_t, or if the tm contains out of range values.
  41. */
  42. int OPENSSL_timegm(const struct tm *tm, time_t *out);
  43. #if defined(__cplusplus)
  44. } /* extern C */
  45. #endif
  46. #endif /* OPENSSL_HEADER_POSIX_TIME_H */