timegm.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Convert UTC calendar time to simple time. Like mktime but assumes UTC.
  2. Copyright (C) 1994-2023 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. <https://www.gnu.org/licenses/>. */
  15. #ifndef _LIBC
  16. # include <libc-config.h>
  17. #endif
  18. #include <time.h>
  19. #include <errno.h>
  20. #include "mktime-internal.h"
  21. __time64_t
  22. __timegm64 (struct tm *tmp)
  23. {
  24. static mktime_offset_t gmtime_offset;
  25. tmp->tm_isdst = 0;
  26. return __mktime_internal (tmp, __gmtime64_r, &gmtime_offset);
  27. }
  28. #if defined _LIBC && __TIMESIZE != 64
  29. libc_hidden_def (__timegm64)
  30. time_t
  31. timegm (struct tm *tmp)
  32. {
  33. struct tm tm = *tmp;
  34. __time64_t t = __timegm64 (&tm);
  35. if (in_time_t_range (t))
  36. {
  37. *tmp = tm;
  38. return t;
  39. }
  40. else
  41. {
  42. __set_errno (EOVERFLOW);
  43. return -1;
  44. }
  45. }
  46. #endif