diff options
Diffstat (limited to 'gl/timegm.c')
-rw-r--r-- | gl/timegm.c | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/gl/timegm.c b/gl/timegm.c index 6338baa..b47025a 100644 --- a/gl/timegm.c +++ b/gl/timegm.c | |||
@@ -1,38 +1,58 @@ | |||
1 | /* Convert UTC calendar time to simple time. Like mktime but assumes UTC. | 1 | /* Convert UTC calendar time to simple time. Like mktime but assumes UTC. |
2 | 2 | ||
3 | Copyright (C) 1994, 1997, 2003-2004, 2006-2007, 2009-2013 Free Software | 3 | Copyright (C) 1994-2023 Free Software Foundation, Inc. |
4 | Foundation, Inc. This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | The GNU C Library is free software; you can redistribute it and/or |
7 | it under the terms of the GNU General Public License as published by | 7 | modify it under the terms of the GNU Lesser General Public |
8 | the Free Software Foundation; either version 3, or (at your option) | 8 | License as published by the Free Software Foundation; either |
9 | any later version. | 9 | version 2.1 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | GNU General Public License for more details. | 14 | Lesser General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU Lesser General Public |
17 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | 17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ | ||
18 | 19 | ||
19 | #ifndef _LIBC | 20 | #ifndef _LIBC |
20 | # include <config.h> | 21 | # include <libc-config.h> |
21 | #endif | 22 | #endif |
22 | 23 | ||
23 | #include <time.h> | 24 | #include <time.h> |
25 | #include <errno.h> | ||
24 | 26 | ||
25 | #ifndef _LIBC | 27 | #include "mktime-internal.h" |
26 | # undef __gmtime_r | 28 | |
27 | # define __gmtime_r gmtime_r | 29 | __time64_t |
28 | # define __mktime_internal mktime_internal | 30 | __timegm64 (struct tm *tmp) |
29 | # include "mktime-internal.h" | 31 | { |
30 | #endif | 32 | static mktime_offset_t gmtime_offset; |
33 | tmp->tm_isdst = 0; | ||
34 | return __mktime_internal (tmp, __gmtime64_r, &gmtime_offset); | ||
35 | } | ||
36 | |||
37 | #if defined _LIBC && __TIMESIZE != 64 | ||
38 | |||
39 | libc_hidden_def (__timegm64) | ||
31 | 40 | ||
32 | time_t | 41 | time_t |
33 | timegm (struct tm *tmp) | 42 | timegm (struct tm *tmp) |
34 | { | 43 | { |
35 | static time_t gmtime_offset; | 44 | struct tm tm = *tmp; |
36 | tmp->tm_isdst = 0; | 45 | __time64_t t = __timegm64 (&tm); |
37 | return __mktime_internal (tmp, __gmtime_r, &gmtime_offset); | 46 | if (in_time_t_range (t)) |
47 | { | ||
48 | *tmp = tm; | ||
49 | return t; | ||
50 | } | ||
51 | else | ||
52 | { | ||
53 | __set_errno (EOVERFLOW); | ||
54 | return -1; | ||
55 | } | ||
38 | } | 56 | } |
57 | |||
58 | #endif | ||