7 // FIXME: integer overflows
9 const char *__langinfo(nl_item);
11 size_t strftime(char *s, size_t n, const char *f, const struct tm *tm)
17 for (l=0; *f && l<n; f++) {
27 item = ABDAY_1 + tm->tm_wday;
30 item = DAY_1 + tm->tm_wday;
34 item = ABMON_1 + tm->tm_mon;
37 item = MON_1 + tm->tm_mon;
43 val = (1900+tm->tm_year) / 100;
62 val = 0; //week_based_year(tm)%100;
67 val = 0; //week_based_year(tm);
77 else if (val > 12) val -= 12;
96 item = tm->tm_hour >= 12 ? PM_STR : AM_STR;
115 val = tm->tm_wday ? tm->tm_wday : 7;
121 // FIXME: week number mess..
134 val = tm->tm_year % 100;
138 val = tm->tm_year + 1900;
142 if (tm->tm_isdst < 0) continue;
143 val = -__timezone - (tm->tm_isdst ? __dst_offset : 0);
144 l += snprintf(s+l, n-l, "%+.2d%.2d", val/3600, abs(val%3600)/60);
147 if (tm->tm_isdst < 0 || !__tzname[0] || !__tzname[0][0])
149 l += snprintf(s+l, n-l, "%s", __tzname[!!tm->tm_isdst]);
159 l += snprintf(s+l, n-l, fmt, val);
162 l += snprintf(s+l, n-l, "%s", __langinfo(item));
165 fmt = __langinfo(item);
167 l += strftime(s+l, n-l, fmt, tm);
169 if (l >= n) return 0;