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
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;
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);
}
/* Find the standard and daylight time offsets used by the rule file.
We choose the offsets in the types of each flavor that are
transitioned to earliest in time. */
- rule_dstoff = 0;
+ rule_stdoff = rule_dstoff = 0;
for (i = 0; i < num_transitions; ++i)
{
if (!rule_stdoff && !types[type_idxs[i]].isdst)