+ static const unsigned short int month_to_days[][13] = {
+ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, /* normal */
+ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } /* leap */
+ };
+ const int year = 1900 + t->tm_year;
+ unsigned long secs; /* until 2106-02-07 for 32-bit unsigned long */
+ int days;
+
+ if (year < 1970)
+ return (time_t) -1;
+
+ days = 365 * (year - 1970);
+ /* Take into account leap years between 1970 and YEAR, not counting
+ YEAR itself. */
+ days += LEAPYEARS (1970, year);
+ if (t->tm_mon < 0 || t->tm_mon >= 12)
+ return (time_t) -1;
+ days += month_to_days[ISLEAP (year)][t->tm_mon];
+ days += t->tm_mday - 1;
+
+ secs = days * 86400 + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec;
+ return (time_t) secs;
+}
+#endif /* HAVE_TIMEGM */
+
+#ifdef NEED_STRTOLL
+/* strtoll is required by C99 and used by Wget only on systems with
+ LFS. Unfortunately, some systems have LFS, but no strtoll or
+ equivalent. These include HPUX 11.0 and Windows.
+
+ We use #ifdef NEED_STRTOLL instead of #ifndef HAVE_STRTOLL because
+ of the systems which have a suitable replacement (e.g. _strtoi64 on
+ Windows), on which Wget's str_to_wgint is instructed to use that
+ instead. */
+
+static inline int
+char_value (char c, int base)
+{
+ int value;
+ if (c < '0')
+ return -1;
+ if ('0' <= c && c <= '9')
+ value = c - '0';
+ else if ('a' <= c && c <= 'z')
+ value = c - 'a' + 10;
+ else if ('A' <= c && c <= 'Z')
+ value = c - 'A' + 10;
+ else
+ return -1;
+ if (value >= base)
+ return -1;
+ return value;
+}