Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/time')
-rw-r--r--newlib/libc/time/Makefile.am3
-rw-r--r--newlib/libc/time/Makefile.in30
-rw-r--r--newlib/libc/time/clock.c2
-rw-r--r--newlib/libc/time/gmtime_r.c127
-rw-r--r--newlib/libc/time/lcltime_r.c112
-rw-r--r--newlib/libc/time/local.h3
-rw-r--r--newlib/libc/time/mktm_r.c259
-rw-r--r--newlib/libc/time/month_lengths.c14
-rw-r--r--newlib/libc/time/strftime.c6
-rw-r--r--newlib/libc/time/strptime.c2
-rw-r--r--newlib/libc/time/tzcalc_limits.c77
11 files changed, 281 insertions, 354 deletions
diff --git a/newlib/libc/time/Makefile.am b/newlib/libc/time/Makefile.am
index 95f088a51..95716315b 100644
--- a/newlib/libc/time/Makefile.am
+++ b/newlib/libc/time/Makefile.am
@@ -17,11 +17,10 @@ LIB_SOURCES = \
lcltime.c \
lcltime_r.c \
mktime.c \
- month_lengths.c \
+ mktm_r.c \
strftime.c \
strptime.c \
time.c \
- tzcalc_limits.c \
tzlock.c \
tzset.c \
tzset_r.c \
diff --git a/newlib/libc/time/Makefile.in b/newlib/libc/time/Makefile.in
index 48ba064ca..c28caaf9c 100644
--- a/newlib/libc/time/Makefile.in
+++ b/newlib/libc/time/Makefile.in
@@ -78,20 +78,19 @@ am__objects_1 = lib_a-asctime.$(OBJEXT) lib_a-asctime_r.$(OBJEXT) \
lib_a-gettzinfo.$(OBJEXT) lib_a-gmtime.$(OBJEXT) \
lib_a-gmtime_r.$(OBJEXT) lib_a-lcltime.$(OBJEXT) \
lib_a-lcltime_r.$(OBJEXT) lib_a-mktime.$(OBJEXT) \
- lib_a-month_lengths.$(OBJEXT) lib_a-strftime.$(OBJEXT) \
+ lib_a-mktm_r.$(OBJEXT) lib_a-strftime.$(OBJEXT) \
lib_a-strptime.$(OBJEXT) lib_a-time.$(OBJEXT) \
- lib_a-tzcalc_limits.$(OBJEXT) lib_a-tzlock.$(OBJEXT) \
- lib_a-tzset.$(OBJEXT) lib_a-tzset_r.$(OBJEXT) \
- lib_a-tzvars.$(OBJEXT) lib_a-wcsftime.$(OBJEXT)
+ lib_a-tzlock.$(OBJEXT) lib_a-tzset.$(OBJEXT) \
+ lib_a-tzset_r.$(OBJEXT) lib_a-tzvars.$(OBJEXT) \
+ lib_a-wcsftime.$(OBJEXT)
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
LTLIBRARIES = $(noinst_LTLIBRARIES)
libtime_la_LIBADD =
am__objects_2 = asctime.lo asctime_r.lo clock.lo ctime.lo ctime_r.lo \
difftime.lo gettzinfo.lo gmtime.lo gmtime_r.lo lcltime.lo \
- lcltime_r.lo mktime.lo month_lengths.lo strftime.lo \
- strptime.lo time.lo tzcalc_limits.lo tzlock.lo tzset.lo \
- tzset_r.lo tzvars.lo wcsftime.lo
+ lcltime_r.lo mktime.lo mktm_r.lo strftime.lo strptime.lo \
+ time.lo tzlock.lo tzset.lo tzset_r.lo tzvars.lo wcsftime.lo
@USE_LIBTOOL_TRUE@am_libtime_la_OBJECTS = $(am__objects_2)
libtime_la_OBJECTS = $(am_libtime_la_OBJECTS)
libtime_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -278,11 +277,10 @@ LIB_SOURCES = \
lcltime.c \
lcltime_r.c \
mktime.c \
- month_lengths.c \
+ mktm_r.c \
strftime.c \
strptime.c \
time.c \
- tzcalc_limits.c \
tzlock.c \
tzset.c \
tzset_r.c \
@@ -456,11 +454,11 @@ lib_a-mktime.o: mktime.c
lib_a-mktime.obj: mktime.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mktime.obj `if test -f 'mktime.c'; then $(CYGPATH_W) 'mktime.c'; else $(CYGPATH_W) '$(srcdir)/mktime.c'; fi`
-lib_a-month_lengths.o: month_lengths.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-month_lengths.o `test -f 'month_lengths.c' || echo '$(srcdir)/'`month_lengths.c
+lib_a-mktm_r.o: mktm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mktm_r.o `test -f 'mktm_r.c' || echo '$(srcdir)/'`mktm_r.c
-lib_a-month_lengths.obj: month_lengths.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-month_lengths.obj `if test -f 'month_lengths.c'; then $(CYGPATH_W) 'month_lengths.c'; else $(CYGPATH_W) '$(srcdir)/month_lengths.c'; fi`
+lib_a-mktm_r.obj: mktm_r.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mktm_r.obj `if test -f 'mktm_r.c'; then $(CYGPATH_W) 'mktm_r.c'; else $(CYGPATH_W) '$(srcdir)/mktm_r.c'; fi`
lib_a-strftime.o: strftime.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strftime.o `test -f 'strftime.c' || echo '$(srcdir)/'`strftime.c
@@ -480,12 +478,6 @@ lib_a-time.o: time.c
lib_a-time.obj: time.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-time.obj `if test -f 'time.c'; then $(CYGPATH_W) 'time.c'; else $(CYGPATH_W) '$(srcdir)/time.c'; fi`
-lib_a-tzcalc_limits.o: tzcalc_limits.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-tzcalc_limits.o `test -f 'tzcalc_limits.c' || echo '$(srcdir)/'`tzcalc_limits.c
-
-lib_a-tzcalc_limits.obj: tzcalc_limits.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-tzcalc_limits.obj `if test -f 'tzcalc_limits.c'; then $(CYGPATH_W) 'tzcalc_limits.c'; else $(CYGPATH_W) '$(srcdir)/tzcalc_limits.c'; fi`
-
lib_a-tzlock.o: tzlock.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-tzlock.o `test -f 'tzlock.c' || echo '$(srcdir)/'`tzlock.c
diff --git a/newlib/libc/time/clock.c b/newlib/libc/time/clock.c
index 0bcfbb6d3..64cf438fb 100644
--- a/newlib/libc/time/clock.c
+++ b/newlib/libc/time/clock.c
@@ -59,7 +59,7 @@ clock ()
struct tms tim_s;
clock_t res;
- if ((res = (clock_t) _times_r (_REENT, &tim_s)) != (clock_t) -1)
+ if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1)
res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime +
tim_s.tms_cutime + tim_s.tms_cstime);
diff --git a/newlib/libc/time/gmtime_r.c b/newlib/libc/time/gmtime_r.c
index f50c199b9..14c9c7640 100644
--- a/newlib/libc/time/gmtime_r.c
+++ b/newlib/libc/time/gmtime_r.c
@@ -1,137 +1,14 @@
/*
* gmtime_r.c
- * Original Author: Adapted from tzcode maintained by Arthur David Olson.
- * Modifications:
- * - Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston
- * - Fixed bug in mday computations - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
- * - Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
- * - Move code from _mktm_r() to gmtime_r() - 05/09/14, Freddie Chopin <freddie_chopin@op.pl>
- * - Fixed bug in calculations for dates after year 2069 or before year 1901. Ideas for
- * solution taken from musl's __secs_to_tm() - 07/12/2014, Freddie Chopin
- * <freddie_chopin@op.pl>
- *
- * Converts the calendar time pointed to by tim_p into a broken-down time
- * expressed as local time. Returns a pointer to a structure containing the
- * broken-down time.
*/
+#include <time.h>
#include "local.h"
-/* move epoch from 01.01.1970 to 01.03.2000 - this is the first day of new
- * 400-year long cycle, right after additional day of leap year. This adjustment
- * is required only for date calculation, so instead of modifying time_t value
- * (which would require 64-bit operations to work correctly) it's enough to
- * adjust the calculated number of days since epoch. */
-#define EPOCH_ADJUSTMENT_DAYS 11017
-/* year to which the adjustment was made */
-#define ADJUSTED_EPOCH_YEAR 2000
-/* 1st March of 2000 is Wednesday */
-#define ADJUSTED_EPOCH_WDAY 3
-/* there are 97 leap years in 400-year periods. ((400 - 97) * 365 + 97 * 366) */
-#define DAYS_PER_400_YEARS 146097L
-/* there are 24 leap years in 100-year periods. ((100 - 24) * 365 + 24 * 366) */
-#define DAYS_PER_100_YEARS 36524L
-/* there is one leap year every 4 years */
-#define DAYS_PER_4_YEARS (3 * 365 + 366)
-/* number of days in a non-leap year */
-#define DAYS_PER_YEAR 365
-/* number of days in January */
-#define DAYS_IN_JANUARY 31
-/* number of days in non-leap February */
-#define DAYS_IN_FEBRUARY 28
-
struct tm *
_DEFUN (gmtime_r, (tim_p, res),
_CONST time_t *__restrict tim_p _AND
struct tm *__restrict res)
{
- long days, rem;
- _CONST time_t lcltime = *tim_p;
- int year, month, yearday, weekday;
- int years400, years100, years4, remainingyears;
- int yearleap;
- _CONST int *ip;
-
- days = ((long)lcltime) / SECSPERDAY - EPOCH_ADJUSTMENT_DAYS;
- rem = ((long)lcltime) % SECSPERDAY;
- if (rem < 0)
- {
- rem += SECSPERDAY;
- --days;
- }
-
- /* compute hour, min, and sec */
- res->tm_hour = (int) (rem / SECSPERHOUR);
- rem %= SECSPERHOUR;
- res->tm_min = (int) (rem / SECSPERMIN);
- res->tm_sec = (int) (rem % SECSPERMIN);
-
- /* compute day of week */
- if ((weekday = ((ADJUSTED_EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
- weekday += DAYSPERWEEK;
- res->tm_wday = weekday;
-
- /* compute year & day of year */
- years400 = days / DAYS_PER_400_YEARS;
- days -= years400 * DAYS_PER_400_YEARS;
- /* simplify by making the values positive */
- if (days < 0)
- {
- days += DAYS_PER_400_YEARS;
- --years400;
- }
-
- years100 = days / DAYS_PER_100_YEARS;
- if (years100 == 4) /* required for proper day of year calculation */
- --years100;
- days -= years100 * DAYS_PER_100_YEARS;
- years4 = days / DAYS_PER_4_YEARS;
- days -= years4 * DAYS_PER_4_YEARS;
- remainingyears = days / DAYS_PER_YEAR;
- if (remainingyears == 4) /* required for proper day of year calculation */
- --remainingyears;
- days -= remainingyears * DAYS_PER_YEAR;
-
- year = ADJUSTED_EPOCH_YEAR + years400 * 400 + years100 * 100 + years4 * 4 +
- remainingyears;
-
- /* If remainingyears is zero, it means that the years were completely
- * "consumed" by modulo calculations by 400, 100 and 4, so the year is:
- * 1. a multiple of 4, but not a multiple of 100 or 400 - it's a leap year,
- * 2. a multiple of 4 and 100, but not a multiple of 400 - it's not a leap
- * year,
- * 3. a multiple of 4, 100 and 400 - it's a leap year.
- * If years4 is non-zero, it means that the year is not a multiple of 100 or
- * 400 (case 1), so it's a leap year. If years100 is zero (and years4 is zero
- * - due to short-circuiting), it means that the year is a multiple of 400
- * (case 3), so it's also a leap year. */
- yearleap = remainingyears == 0 && (years4 != 0 || years100 == 0);
-
- /* adjust back to 1st January */
- yearday = days + DAYS_IN_JANUARY + DAYS_IN_FEBRUARY + yearleap;
- if (yearday >= DAYS_PER_YEAR + yearleap)
- {
- yearday -= DAYS_PER_YEAR + yearleap;
- ++year;
- }
- res->tm_yday = yearday;
- res->tm_year = year - YEAR_BASE;
-
- /* Because "days" is the number of days since 1st March, the additional leap
- * day (29th of February) is the last possible day, so it doesn't matter much
- * whether the year is actually leap or not. */
- ip = __month_lengths[1];
- month = 2;
- while (days >= ip[month])
- {
- days -= ip[month];
- if (++month >= MONSPERYEAR)
- month = 0;
- }
- res->tm_mon = month;
- res->tm_mday = days + 1;
-
- res->tm_isdst = 0;
-
- return (res);
+ return (_mktm_r (tim_p, res, 1));
}
diff --git a/newlib/libc/time/lcltime_r.c b/newlib/libc/time/lcltime_r.c
index 9094e5d3a..9e168aa3f 100644
--- a/newlib/libc/time/lcltime_r.c
+++ b/newlib/libc/time/lcltime_r.c
@@ -1,18 +1,12 @@
/*
* localtime_r.c
- * Original Author: Adapted from tzcode maintained by Arthur David Olson.
- * Modifications:
- * - Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston
- * - Fixed bug in mday computations - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
- * - Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
- * - Implement localtime_r() with gmtime_r() and the conditional code moved
- * from _mktm_r() - 05/09/14, Freddie Chopin <freddie_chopin@op.pl>
*
* Converts the calendar time pointed to by tim_p into a broken-down time
* expressed as local time. Returns a pointer to a structure containing the
* broken-down time.
*/
+#include <time.h>
#include "local.h"
struct tm *
@@ -20,107 +14,5 @@ _DEFUN (localtime_r, (tim_p, res),
_CONST time_t *__restrict tim_p _AND
struct tm *__restrict res)
{
- long offset;
- int hours, mins, secs;
- int year;
- __tzinfo_type *_CONST tz = __gettzinfo ();
- _CONST int *ip;
-
- res = gmtime_r (tim_p, res);
-
- year = res->tm_year + YEAR_BASE;
- ip = __month_lengths[isleap(year)];
-
- TZ_LOCK;
- if (_daylight)
- {
- if (year == tz->__tzyear || __tzcalc_limits (year))
- res->tm_isdst = (tz->__tznorth
- ? (*tim_p >= tz->__tzrule[0].change
- && *tim_p < tz->__tzrule[1].change)
- : (*tim_p >= tz->__tzrule[0].change
- || *tim_p < tz->__tzrule[1].change));
- else
- res->tm_isdst = -1;
- }
- else
- res->tm_isdst = 0;
-
- offset = (res->tm_isdst == 1
- ? tz->__tzrule[1].offset
- : tz->__tzrule[0].offset);
-
- hours = (int) (offset / SECSPERHOUR);
- offset = offset % SECSPERHOUR;
-
- mins = (int) (offset / SECSPERMIN);
- secs = (int) (offset % SECSPERMIN);
-
- res->tm_sec -= secs;
- res->tm_min -= mins;
- res->tm_hour -= hours;
-
- if (res->tm_sec >= SECSPERMIN)
- {
- res->tm_min += 1;
- res->tm_sec -= SECSPERMIN;
- }
- else if (res->tm_sec < 0)
- {
- res->tm_min -= 1;
- res->tm_sec += SECSPERMIN;
- }
- if (res->tm_min >= MINSPERHOUR)
- {
- res->tm_hour += 1;
- res->tm_min -= MINSPERHOUR;
- }
- else if (res->tm_min < 0)
- {
- res->tm_hour -= 1;
- res->tm_min += MINSPERHOUR;
- }
- if (res->tm_hour >= HOURSPERDAY)
- {
- ++res->tm_yday;
- ++res->tm_wday;
- if (res->tm_wday > 6)
- res->tm_wday = 0;
- ++res->tm_mday;
- res->tm_hour -= HOURSPERDAY;
- if (res->tm_mday > ip[res->tm_mon])
- {
- res->tm_mday -= ip[res->tm_mon];
- res->tm_mon += 1;
- if (res->tm_mon == 12)
- {
- res->tm_mon = 0;
- res->tm_year += 1;
- res->tm_yday = 0;
- }
- }
- }
- else if (res->tm_hour < 0)
- {
- res->tm_yday -= 1;
- res->tm_wday -= 1;
- if (res->tm_wday < 0)
- res->tm_wday = 6;
- res->tm_mday -= 1;
- res->tm_hour += 24;
- if (res->tm_mday == 0)
- {
- res->tm_mon -= 1;
- if (res->tm_mon < 0)
- {
- res->tm_mon = 11;
- res->tm_year -= 1;
- res->tm_yday = 364 + isleap(res->tm_year + YEAR_BASE);
- }
- res->tm_mday = ip[res->tm_mon];
- }
- }
- TZ_UNLOCK;
-
- return (res);
+ return _mktm_r (tim_p, res, 0);
}
diff --git a/newlib/libc/time/local.h b/newlib/libc/time/local.h
index 5fc3ddcb1..9d9ef87fa 100644
--- a/newlib/libc/time/local.h
+++ b/newlib/libc/time/local.h
@@ -19,10 +19,9 @@
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
+struct tm * _EXFUN (_mktm_r, (_CONST time_t *, struct tm *, int __is_gmtime));
int _EXFUN (__tzcalc_limits, (int __year));
-extern _CONST int __month_lengths[2][MONSPERYEAR];
-
/* locks for multi-threading */
#ifdef __SINGLE_THREAD__
#define TZ_LOCK
diff --git a/newlib/libc/time/mktm_r.c b/newlib/libc/time/mktm_r.c
new file mode 100644
index 000000000..9a3bc820e
--- /dev/null
+++ b/newlib/libc/time/mktm_r.c
@@ -0,0 +1,259 @@
+/*
+ * mktm_r.c
+ * Original Author: Adapted from tzcode maintained by Arthur David Olson.
+ * Modifications: Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston
+ * Fixed bug in mday computations - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
+ * Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
+ *
+ * Converts the calendar time pointed to by tim_p into a broken-down time
+ * expressed as local time. Returns a pointer to a structure containing the
+ * broken-down time.
+ */
+
+#include <stdlib.h>
+#include <time.h>
+#include "local.h"
+
+static _CONST int mon_lengths[2][MONSPERYEAR] = {
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
+ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
+} ;
+
+static _CONST int year_lengths[2] = {
+ 365,
+ 366
+} ;
+
+struct tm *
+_DEFUN (_mktm_r, (tim_p, res, is_gmtime),
+ _CONST time_t * tim_p _AND
+ struct tm *res _AND
+ int is_gmtime)
+{
+ long days, rem;
+ time_t lcltime;
+ int y;
+ int yleap;
+ _CONST int *ip;
+ __tzinfo_type *tz = __gettzinfo ();
+
+ /* base decision about std/dst time on current time */
+ lcltime = *tim_p;
+
+ days = ((long)lcltime) / SECSPERDAY;
+ rem = ((long)lcltime) % SECSPERDAY;
+ while (rem < 0)
+ {
+ rem += SECSPERDAY;
+ --days;
+ }
+ while (rem >= SECSPERDAY)
+ {
+ rem -= SECSPERDAY;
+ ++days;
+ }
+
+ /* compute hour, min, and sec */
+ res->tm_hour = (int) (rem / SECSPERHOUR);
+ rem %= SECSPERHOUR;
+ res->tm_min = (int) (rem / SECSPERMIN);
+ res->tm_sec = (int) (rem % SECSPERMIN);
+
+ /* compute day of week */
+ if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
+ res->tm_wday += DAYSPERWEEK;
+
+ /* compute year & day of year */
+ y = EPOCH_YEAR;
+ if (days >= 0)
+ {
+ for (;;)
+ {
+ yleap = isleap(y);
+ if (days < year_lengths[yleap])
+ break;
+ y++;
+ days -= year_lengths[yleap];
+ }
+ }
+ else
+ {
+ do
+ {
+ --y;
+ yleap = isleap(y);
+ days += year_lengths[yleap];
+ } while (days < 0);
+ }
+
+ res->tm_year = y - YEAR_BASE;
+ res->tm_yday = days;
+ ip = mon_lengths[yleap];
+ for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon)
+ days -= ip[res->tm_mon];
+ res->tm_mday = days + 1;
+
+ if (!is_gmtime)
+ {
+ long offset;
+ int hours, mins, secs;
+
+ TZ_LOCK;
+ if (_daylight)
+ {
+ if (y == tz->__tzyear || __tzcalc_limits (y))
+ res->tm_isdst = (tz->__tznorth
+ ? (*tim_p >= tz->__tzrule[0].change
+ && *tim_p < tz->__tzrule[1].change)
+ : (*tim_p >= tz->__tzrule[0].change
+ || *tim_p < tz->__tzrule[1].change));
+ else
+ res->tm_isdst = -1;
+ }
+ else
+ res->tm_isdst = 0;
+
+ offset = (res->tm_isdst == 1
+ ? tz->__tzrule[1].offset
+ : tz->__tzrule[0].offset);
+
+ hours = (int) (offset / SECSPERHOUR);
+ offset = offset % SECSPERHOUR;
+
+ mins = (int) (offset / SECSPERMIN);
+ secs = (int) (offset % SECSPERMIN);
+
+ res->tm_sec -= secs;
+ res->tm_min -= mins;
+ res->tm_hour -= hours;
+
+ if (res->tm_sec >= SECSPERMIN)
+ {
+ res->tm_min += 1;
+ res->tm_sec -= SECSPERMIN;
+ }
+ else if (res->tm_sec < 0)
+ {
+ res->tm_min -= 1;
+ res->tm_sec += SECSPERMIN;
+ }
+ if (res->tm_min >= MINSPERHOUR)
+ {
+ res->tm_hour += 1;
+ res->tm_min -= MINSPERHOUR;
+ }
+ else if (res->tm_min < 0)
+ {
+ res->tm_hour -= 1;
+ res->tm_min += MINSPERHOUR;
+ }
+ if (res->tm_hour >= HOURSPERDAY)
+ {
+ ++res->tm_yday;
+ ++res->tm_wday;
+ if (res->tm_wday > 6)
+ res->tm_wday = 0;
+ ++res->tm_mday;
+ res->tm_hour -= HOURSPERDAY;
+ if (res->tm_mday > ip[res->tm_mon])
+ {
+ res->tm_mday -= ip[res->tm_mon];
+ res->tm_mon += 1;
+ if (res->tm_mon == 12)
+ {
+ res->tm_mon = 0;
+ res->tm_year += 1;
+ res->tm_yday = 0;
+ }
+ }
+ }
+ else if (res->tm_hour < 0)
+ {
+ res->tm_yday -= 1;
+ res->tm_wday -= 1;
+ if (res->tm_wday < 0)
+ res->tm_wday = 6;
+ res->tm_mday -= 1;
+ res->tm_hour += 24;
+ if (res->tm_mday == 0)
+ {
+ res->tm_mon -= 1;
+ if (res->tm_mon < 0)
+ {
+ res->tm_mon = 11;
+ res->tm_year -= 1;
+ res->tm_yday = 364 + isleap(res->tm_year + 1900);
+ }
+ res->tm_mday = ip[res->tm_mon];
+ }
+ }
+ TZ_UNLOCK;
+ }
+ else
+ res->tm_isdst = 0;
+
+ return (res);
+}
+
+int
+_DEFUN (__tzcalc_limits, (year),
+ int year)
+{
+ int days, year_days, years;
+ int i, j;
+ __tzinfo_type *tz = __gettzinfo ();
+
+ if (year < EPOCH_YEAR)
+ return 0;
+
+ tz->__tzyear = year;
+
+ years = (year - EPOCH_YEAR);
+
+ year_days = years * 365 +
+ (years - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 - (years - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 +
+ (years - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400;
+
+ for (i = 0; i < 2; ++i)
+ {
+ if (tz->__tzrule[i].ch == 'J') {
+ /* The Julian day n (1 <= n <= 365). */
+ days = year_days + tz->__tzrule[i].d +
+ (isleap(year) && tz->__tzrule[i].d >= 60);
+ /* Convert to yday */
+ --days;
+ } else if (tz->__tzrule[i].ch == 'D')
+ days = year_days + tz->__tzrule[i].d;
+ else
+ {
+ int yleap = isleap(year);
+ int m_day, m_wday, wday_diff;
+ _CONST int *ip = mon_lengths[yleap];
+
+ days = year_days;
+
+ for (j = 1; j < tz->__tzrule[i].m; ++j)
+ days += ip[j-1];
+
+ m_wday = (EPOCH_WDAY + days) % DAYSPERWEEK;
+
+ wday_diff = tz->__tzrule[i].d - m_wday;
+ if (wday_diff < 0)
+ wday_diff += DAYSPERWEEK;
+ m_day = (tz->__tzrule[i].n - 1) * DAYSPERWEEK + wday_diff;
+
+ while (m_day >= ip[j-1])
+ m_day -= DAYSPERWEEK;
+
+ days += m_day;
+ }
+
+ /* store the change-over time in GMT form by adding offset */
+ tz->__tzrule[i].change = days * SECSPERDAY +
+ tz->__tzrule[i].s + tz->__tzrule[i].offset;
+ }
+
+ tz->__tznorth = (tz->__tzrule[0].change < tz->__tzrule[1].change);
+
+ return 1;
+}
diff --git a/newlib/libc/time/month_lengths.c b/newlib/libc/time/month_lengths.c
deleted file mode 100644
index 2871802f0..000000000
--- a/newlib/libc/time/month_lengths.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * month_lengths.c
- *
- * Array __month_lengths[] is (indirectly) needed by tzset(), mktime(),
- * gmtime() and localtime(). To break any dependencies, this array is moved to
- * separate source file.
- */
-
-#include "local.h"
-
-_CONST int __month_lengths[2][MONSPERYEAR] = {
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
-} ;
diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c
index 9bdde829a..f95a85dce 100644
--- a/newlib/libc/time/strftime.c
+++ b/newlib/libc/time/strftime.c
@@ -694,12 +694,12 @@ _DEFUN (strftime, (s, maxsize, format, tim_p),
#endif /* !_WANT_C99_TIME_FORMATS */
{
size_t count = 0;
- int len = 0;
+ int i, len = 0;
const CHAR *ctloc;
#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
CHAR ctlocbuf[CTLOCBUFLEN];
#endif
- size_t i, ctloclen;
+ size_t ctloclen;
CHAR alt;
CHAR pad;
unsigned long width;
@@ -1299,7 +1299,7 @@ recurse:
case CQ('Z'):
if (tim_p->tm_isdst >= 0)
{
- size_t size;
+ int size;
TZ_LOCK;
size = strlen(_tzname[tim_p->tm_isdst > 0]);
for (i = 0; i < size; i++)
diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
index 19b9fcede..d7dd7a2b2 100644
--- a/newlib/libc/time/strptime.c
+++ b/newlib/libc/time/strptime.c
@@ -68,7 +68,7 @@ is_leap_year (int year)
/* Needed for strptime. */
static int
-match_string (const char *__restrict *buf, const char **strs)
+match_string (const char **buf, const char **strs)
{
int i = 0;
diff --git a/newlib/libc/time/tzcalc_limits.c b/newlib/libc/time/tzcalc_limits.c
deleted file mode 100644
index 8a0bda3da..000000000
--- a/newlib/libc/time/tzcalc_limits.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * tzcalc_limits.c
- * Original Author: Adapted from tzcode maintained by Arthur David Olson.
- * Modifications:
- * - Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston
- * - Fixed bug in mday computations - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
- * - Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru>
- * - Moved __tzcalc_limits() to separate file - 05/09/14, Freddie Chopin <freddie_chopin@op.pl>
- */
-
-#include "local.h"
-
-int
-_DEFUN (__tzcalc_limits, (year),
- int year)
-{
- int days, year_days, years;
- int i, j;
- __tzinfo_type *_CONST tz = __gettzinfo ();
-
- if (year < EPOCH_YEAR)
- return 0;
-
- tz->__tzyear = year;
-
- years = (year - EPOCH_YEAR);
-
- year_days = years * 365 +
- (years - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 -
- (years - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 +
- (years - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400;
-
- for (i = 0; i < 2; ++i)
- {
- if (tz->__tzrule[i].ch == 'J')
- {
- /* The Julian day n (1 <= n <= 365). */
- days = year_days + tz->__tzrule[i].d +
- (isleap(year) && tz->__tzrule[i].d >= 60);
- /* Convert to yday */
- --days;
- }
- else if (tz->__tzrule[i].ch == 'D')
- days = year_days + tz->__tzrule[i].d;
- else
- {
- _CONST int yleap = isleap(year);
- int m_day, m_wday, wday_diff;
- _CONST int *_CONST ip = __month_lengths[yleap];
-
- days = year_days;
-
- for (j = 1; j < tz->__tzrule[i].m; ++j)
- days += ip[j-1];
-
- m_wday = (EPOCH_WDAY + days) % DAYSPERWEEK;
-
- wday_diff = tz->__tzrule[i].d - m_wday;
- if (wday_diff < 0)
- wday_diff += DAYSPERWEEK;
- m_day = (tz->__tzrule[i].n - 1) * DAYSPERWEEK + wday_diff;
-
- while (m_day >= ip[j-1])
- m_day -= DAYSPERWEEK;
-
- days += m_day;
- }
-
- /* store the change-over time in GMT form by adding offset */
- tz->__tzrule[i].change = days * SECSPERDAY +
- tz->__tzrule[i].s + tz->__tzrule[i].offset;
- }
-
- tz->__tznorth = (tz->__tzrule[0].change < tz->__tzrule[1].change);
-
- return 1;
-}