mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 14:00:30 +00:00
20aa581958
Keep these functions compatible with Gnulib while adding __time64_t support. The basic idea is to move private API declarations from include/time.h to time/mktime-internal.h, since the former file cannot easily be shared with Gnulib whereas the latter can. Also, do some other minor cleanup while in the neighborhood. * include/time.h: Include stdbool.h, time/mktime-internal.h. (__mktime_internal): Move this prototype to time/mktime-internal.h, since Gnulib needs it. (__localtime64_r, __gmtime64_r) [__TIMESIZE == 64]: Move these macros to time/mktime-internal.h, since Gnulib needs them. (__mktime64, __timegm64) [__TIMESIZE != 64]: New prototypes. (in_time_t_range): New static function. * posix/bits/types.h (__time64_t) [__TIMESIZE == 64 && !defined __LIBC]: Do not define as a macro in this case, so that portable code is less tempted to use __time64_t. * time/mktime-internal.h: Rewrite so that it does both glibc and Gnulib work. Include time.h if not _LIBC. (mktime_offset_t) [!_LIBC]: Define for gnulib. (__time64_t, __gmtime64_r, __localtime64_r, __mktime64, __timegm64) [!_LIBC || __TIMESIZE == 64]: New macros, mostly moved here from include/time.h. (__gmtime_r, __localtime_r, __mktime_internal) [!_LIBC]: New macros, taken from GNulib. (__mktime_internal): New prototype, moved here from include/time.h. * time/mktime.c (mktime_min, mktime_max, convert_time) (ranged_convert, __mktime_internal, __mktime64): * time/timegm.c (__timegm64): Use __time64_t, not time_t. * time/mktime.c: Stop worrying about whether time_t is floating-point. (__mktime64) [! (_LIBC && __TIMESIZE != 64)]: Rename from mktime. (mktime) [_LIBC && __TIMESIZE != 64]: New function. * time/timegm.c [!_LIBC]: Include libc-config.h, not config.h, for libc_hidden_def. Include errno.h. (__timegm64) [! (_LIBC && __TIMESIZE != 64)]: Rename from timegm. (timegm) [_LIBC && __TIMESIZE != 64]: New function. First cut at publicizing __time64_t
59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
/* Convert UTC calendar time to simple time. Like mktime but assumes UTC.
|
|
|
|
Copyright (C) 1994-2019 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef _LIBC
|
|
# include <libc-config.h>
|
|
#endif
|
|
|
|
#include <time.h>
|
|
#include <errno.h>
|
|
|
|
#include "mktime-internal.h"
|
|
|
|
__time64_t
|
|
__timegm64 (struct tm *tmp)
|
|
{
|
|
static mktime_offset_t gmtime_offset;
|
|
tmp->tm_isdst = 0;
|
|
return __mktime_internal (tmp, __gmtime64_r, &gmtime_offset);
|
|
}
|
|
|
|
#if defined _LIBC && __TIMESIZE != 64
|
|
|
|
libc_hidden_def (__timegm64)
|
|
|
|
time_t
|
|
timegm (struct tm *tmp)
|
|
{
|
|
struct tm tm = *tmp;
|
|
__time64_t t = __timegm64 (&tm);
|
|
if (in_time_t_range (t))
|
|
{
|
|
*tmp = tm;
|
|
return t;
|
|
}
|
|
else
|
|
{
|
|
__set_errno (EOVERFLOW);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
#endif
|