localtime.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Convert `time_t' to `struct tm' in local time zone.
  2. Copyright (C) 1991-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <time.h>
  16. /* The C Standard says that localtime and gmtime return the same pointer. */
  17. struct tm _tmbuf;
  18. /* Return the `struct tm' representation of *T in local time,
  19. using *TP to store the result. */
  20. struct tm *
  21. __localtime64_r (const __time64_t *t, struct tm *tp)
  22. {
  23. return __tz_convert (*t, 1, tp);
  24. }
  25. /* Provide a 32-bit variant if needed. */
  26. #if __TIMESIZE != 64
  27. struct tm *
  28. __localtime_r (const time_t *t, struct tm *tp)
  29. {
  30. __time64_t t64 = *t;
  31. return __localtime64_r (&t64, tp);
  32. }
  33. libc_hidden_def (__localtime64_r)
  34. #endif
  35. weak_alias (__localtime_r, localtime_r)
  36. /* Return the `struct tm' representation of *T in local time. */
  37. struct tm *
  38. __localtime64 (const __time64_t *t)
  39. {
  40. return __tz_convert (*t, 1, &_tmbuf);
  41. }
  42. libc_hidden_def (__localtime64)
  43. /* Provide a 32-bit variant if needed. */
  44. #if __TIMESIZE != 64
  45. struct tm *
  46. localtime (const time_t *t)
  47. {
  48. __time64_t t64 = *t;
  49. return __localtime64 (&t64);
  50. }
  51. libc_hidden_def (localtime)
  52. #endif