mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-26 06:50:07 +00:00
80fd73873b
Rewrite mktime from scratch for performance, and for correctness in the presence of leap seconds. * time/mktime.c (ydhms_tm_diff, not_equal_tm, print_tm, check_result): New functions. (LEAP_SECONDS_POSSIBLE, CHAR_BIT, INT_MIN, INT_MAX, TIME_T_MIN, TIME_T_MAX, TM_YEAR_BASE, EPOCH_YEAR): New macros. <limits.h>, <stdlib.h>: New #includes. (main): Support tests with given broken-down value; support benchmarks. (__mon_lengths, debugging_enabled, printtm, dist_tm, doit, do_normalization, normalize, BAD_STRUCT_TM, SKIP_VALUE, <ctype.h>): Remove. * time/time.h, time/mktime.c (__mktime_internal): New offset arg. * time/mktime.c (mktime), time/timegm.c (timegm): Use it. * time/mktime.c (__mon_yday): New variable; replaces `__mon_lengths'. time/offtime.c (__offtime), time/tzset.c (compute_change): Use it. * time/offtime.c (__offtime): Remove useless assignment `tp->tm_isdst = -1'. * manual/maint.texi: Update credits. Fri Oct 6 00:28:53 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> * sysdeps/unix/common/readv.S: Moved to sysdeps/unix/bsd. * sysdeps/unix/common/writev.S: Moved to sysdeps/unix/bsd. * sysdeps/unix/sysv/linux/readv.c: File removed. * sysdeps/unix/sysv/linux/writev.c: File removed. * sysdeps/unix/configure.in: Check for readv and writev syscalls. * sysdeps/unix/configure.in: If eval doesn't set $unix_srcname, set it to $unix_syscall instead of $unix_function.
81 lines
2.2 KiB
C
81 lines
2.2 KiB
C
/* Copyright (C) 1991, 1993 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 Library General Public License as
|
|
published by the Free Software Foundation; either version 2 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
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
|
Cambridge, MA 02139, USA. */
|
|
|
|
#include <ansidecl.h>
|
|
#include <time.h>
|
|
|
|
|
|
/* Defined in mktime.c. */
|
|
extern CONST unsigned short int __mon_yday[2][13];
|
|
|
|
#define SECS_PER_HOUR (60 * 60)
|
|
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
|
|
|
|
/* Compute the `struct tm' representation of *T,
|
|
offset OFFSET seconds east of UTC,
|
|
and store year, yday, mon, mday, wday, hour, min, sec into *TP. */
|
|
void
|
|
DEFUN(__offtime, (t, offset, tp),
|
|
CONST time_t *t AND long int offset AND struct tm *tp)
|
|
{
|
|
register long int days, rem;
|
|
register int y;
|
|
register CONST unsigned short int *ip;
|
|
|
|
days = *t / SECS_PER_DAY;
|
|
rem = *t % SECS_PER_DAY;
|
|
rem += offset;
|
|
while (rem < 0)
|
|
{
|
|
rem += SECS_PER_DAY;
|
|
--days;
|
|
}
|
|
while (rem >= SECS_PER_DAY)
|
|
{
|
|
rem -= SECS_PER_DAY;
|
|
++days;
|
|
}
|
|
tp->tm_hour = rem / SECS_PER_HOUR;
|
|
rem %= SECS_PER_HOUR;
|
|
tp->tm_min = rem / 60;
|
|
tp->tm_sec = rem % 60;
|
|
/* January 1, 1970 was a Thursday. */
|
|
tp->tm_wday = (4 + days) % 7;
|
|
if (tp->tm_wday < 0)
|
|
tp->tm_wday += 7;
|
|
y = 1970;
|
|
while (days >= (rem = __isleap(y) ? 366 : 365))
|
|
{
|
|
++y;
|
|
days -= rem;
|
|
}
|
|
while (days < 0)
|
|
{
|
|
--y;
|
|
days += __isleap(y) ? 366 : 365;
|
|
}
|
|
tp->tm_year = y - 1900;
|
|
tp->tm_yday = days;
|
|
ip = __mon_yday[__isleap(y)];
|
|
for (y = 11; days < ip[y]; --y)
|
|
continue;
|
|
days -= ip[y];
|
|
tp->tm_mon = y;
|
|
tp->tm_mday = days + 1;
|
|
}
|