mktime-internal.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Internals of mktime and related functions
  2. Copyright 2016-2023 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Paul Eggert <eggert@cs.ucla.edu>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <https://www.gnu.org/licenses/>. */
  16. #ifndef _LIBC
  17. # include <time.h>
  18. #endif
  19. /* mktime_offset_t is a signed type wide enough to hold a UTC offset
  20. in seconds, and used as part of the type of the offset-guess
  21. argument to mktime_internal. In Glibc, it is always long int.
  22. When in Gnulib, use time_t on platforms where time_t
  23. is signed, to be compatible with platforms like BeOS that export
  24. this implementation detail of mktime. On platforms where time_t is
  25. unsigned, GNU and POSIX code can assume 'int' is at least 32 bits
  26. which is wide enough for a UTC offset. */
  27. #ifdef _LIBC
  28. typedef long int mktime_offset_t;
  29. #elif defined TIME_T_IS_SIGNED
  30. typedef time_t mktime_offset_t;
  31. #else
  32. typedef int mktime_offset_t;
  33. #endif
  34. /* The source code uses identifiers like __time64_t for glibc
  35. timestamps that can contain 64-bit values even when time_t is only
  36. 32 bits. These are just macros for the ordinary identifiers unless
  37. compiling within glibc when time_t is 32 bits. */
  38. #if ! (defined _LIBC && __TIMESIZE != 64)
  39. # undef __time64_t
  40. # define __time64_t time_t
  41. # define __gmtime64_r __gmtime_r
  42. # define __localtime64_r __localtime_r
  43. # define __mktime64 mktime
  44. # define __timegm64 timegm
  45. #endif
  46. #ifndef _LIBC
  47. /* Although glibc source code uses leading underscores, Gnulib wants
  48. ordinary names.
  49. Portable standalone applications should supply a <time.h> that
  50. declares a POSIX-compliant localtime_r, for the benefit of older
  51. implementations that lack localtime_r or have a nonstandard one.
  52. Similarly for gmtime_r. See the gnulib time_r module for one way
  53. to implement this. */
  54. # undef __gmtime_r
  55. # undef __localtime_r
  56. # define __gmtime_r gmtime_r
  57. # define __localtime_r localtime_r
  58. # define __mktime_internal mktime_internal
  59. #endif
  60. /* Subroutine of mktime. Return the time_t representation of TP and
  61. normalize TP, given that a struct tm * maps to a time_t as performed
  62. by FUNC. Record next guess for localtime-gmtime offset in *OFFSET. */
  63. extern __time64_t __mktime_internal (struct tm *tp,
  64. struct tm *(*func) (__time64_t const *,
  65. struct tm *),
  66. mktime_offset_t *offset) attribute_hidden;