aboutsummaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
Diffstat (limited to 'time')
-rw-r--r--time/offtime.c24
-rw-r--r--time/strftime.c4
-rw-r--r--time/tzfile.c32
3 files changed, 33 insertions, 27 deletions
diff --git a/time/offtime.c b/time/offtime.c
index 4b8ddb170b..4e062df0d3 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -19,7 +19,6 @@ Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <time.h>
-
/* Defined in mktime.c. */
extern CONST unsigned short int __mon_yday[2][13];
@@ -33,8 +32,7 @@ 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 long int days, rem, y;
register CONST unsigned short int *ip;
days = *t / SECS_PER_DAY;
@@ -59,15 +57,19 @@ DEFUN(__offtime, (t, offset, tp),
if (tp->tm_wday < 0)
tp->tm_wday += 7;
y = 1970;
- while (days >= (rem = __isleap(y) ? 366 : 365))
- {
- ++y;
- days -= rem;
- }
- while (days < 0)
+
+# define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
+
+ while (days < 0 || days >= (__isleap (y) ? 366 : 365))
{
- --y;
- days += __isleap(y) ? 366 : 365;
+ /* Guess a corrected year, assuming 365 days per year. */
+ int yg = y + days / 365 - (days % 365 < 0);
+
+ /* Adjust DAYS and Y to match the guessed year. */
+ days -= ((yg - y) * 365
+ + LEAPS_THRU_END_OF (yg - 1)
+ - LEAPS_THRU_END_OF (y - 1));
+ y = yg;
}
tp->tm_year = y - 1900;
tp->tm_yday = days;
diff --git a/time/strftime.c b/time/strftime.c
index 73f1ac2025..02f72b3164 100644
--- a/time/strftime.c
+++ b/time/strftime.c
@@ -149,7 +149,7 @@ strftime (s, maxsize, format, tp)
const char *const a_month = _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon);
const char *const f_month = _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon);
const char *const ampm = _NL_CURRENT (LC_TIME,
- hour12 > 12 ? PM_STR : AM_STR);
+ hour12 > 11 ? PM_STR : AM_STR);
size_t aw_len = strlen(a_wkday);
size_t am_len = strlen(a_month);
size_t ap_len = strlen (ampm);
@@ -158,7 +158,7 @@ strftime (s, maxsize, format, tp)
const char *const f_month = month_name[tp->tm_mon];
const char *const a_wkday = f_wkday;
const char *const a_month = f_month;
- const char *const ampm = "AMPM" + 2 * (hour12 > 12);
+ const char *const ampm = "AMPM" + 2 * (hour12 > 11);
size_t aw_len = 3;
size_t am_len = 3;
size_t ap_len = 2;
diff --git a/time/tzfile.c b/time/tzfile.c
index cc99802d53..e78a05ec75 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -60,19 +60,20 @@ static struct leap *leaps = NULL;
static inline int
decode (const void *ptr)
{
-#if BYTE_ORDER == BIG_ENDIAN
- return *(const int *) ptr;
-#else
- const unsigned char *p = ptr;
- int result = 0;
-
- result = (result << 8) | *p++;
- result = (result << 8) | *p++;
- result = (result << 8) | *p++;
- result = (result << 8) | *p++;
-
- return result;
-#endif
+ if ((BYTE_ORDER == BIG_ENDIAN) && sizeof (int) == 4)
+ return *(const int *) ptr;
+ else
+ {
+ const unsigned char *p = ptr;
+ int result = *p & (1 << (CHAR_BIT - 1)) ? ~0 : 0;
+
+ result = (result << 8) | *p++;
+ result = (result << 8) | *p++;
+ result = (result << 8) | *p++;
+ result = (result << 8) | *p++;
+
+ return result;
+ }
}
void
@@ -158,6 +159,9 @@ DEFUN(__tzfile_read, (file), CONST char *file)
goto lose;
}
+ if (sizeof (time_t) < 4)
+ abort ();
+
if (fread((PTR) transitions, 4, num_transitions, f) != num_transitions ||
fread((PTR) type_idxs, 1, num_transitions, f) != num_transitions)
goto lose;
@@ -169,7 +173,7 @@ DEFUN(__tzfile_read, (file), CONST char *file)
the array so as not to clobber the next element to be
processed when sizeof (time_t) > 4. */
i = num_transitions;
- while (num_transitions-- > 0)
+ while (i-- > 0)
transitions[i] = decode ((char *) transitions + i*4);
}