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
path: root/newlib
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2014-09-12 20:38:10 +0400
committerJeff Johnston <jjohnstn@redhat.com>2014-09-12 20:38:10 +0400
commit43b3310bc9cb03c9625b0d248ea93392b21c0434 (patch)
treecb8f9a37124eb9a6c842f20005e9c1690c790f2b /newlib
parentc9dded6775ca8a0934739f56c29337a893b5da7c (diff)
2014-09-12 Jeff Johnston <jjohnstn@redhat.com>
* libc/time/month_lengths.c: Actually add file this time. * libc/time/tzcalc_limits.c: Ditto.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog5
-rw-r--r--newlib/libc/time/month_lengths.c14
-rw-r--r--newlib/libc/time/tzcalc_limits.c77
3 files changed, 96 insertions, 0 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 09adf9f06..24c74121b 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,8 @@
+2014-09-12 Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/time/month_lengths.c: Actually add file this time.
+ * libc/time/tzcalc_limits.c: Ditto.
+
2014-09-11 Freddie Chopin <freddie_chopin@op.pl>
* libc/time/month_lengths.c: New file with __month_lengths array
diff --git a/newlib/libc/time/month_lengths.c b/newlib/libc/time/month_lengths.c
new file mode 100644
index 000000000..764e70042
--- /dev/null
+++ b/newlib/libc/time/month_lengths.c
@@ -0,0 +1,14 @@
+/*
+ * 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/tzcalc_limits.c b/newlib/libc/time/tzcalc_limits.c
new file mode 100644
index 000000000..31dda387e
--- /dev/null
+++ b/newlib/libc/time/tzcalc_limits.c
@@ -0,0 +1,77 @@
+/*
+ * 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;
+}