mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 00:08:30 +00:00
Make improvements
- Bump redbean up to 2.0 - Trim down the MODE=tiny build a bit - Add Indian Standard Time to zoneinfo
This commit is contained in:
parent
c9a981fdbe
commit
7aafa64ab3
17 changed files with 233 additions and 179 deletions
|
@ -17,6 +17,7 @@ STATIC_YOINK("usr/share/zoneinfo/Beijing");
|
|||
STATIC_YOINK("usr/share/zoneinfo/Berlin");
|
||||
STATIC_YOINK("usr/share/zoneinfo/Boulder");
|
||||
STATIC_YOINK("usr/share/zoneinfo/Chicago");
|
||||
STATIC_YOINK("usr/share/zoneinfo/GMT");
|
||||
STATIC_YOINK("usr/share/zoneinfo/GST");
|
||||
STATIC_YOINK("usr/share/zoneinfo/Honolulu");
|
||||
STATIC_YOINK("usr/share/zoneinfo/Israel");
|
||||
|
@ -172,10 +173,10 @@ static bool increment_overflow(int *, int);
|
|||
static bool increment_overflow_time(time_t *, int_fast32_t);
|
||||
static int_fast32_t leapcorr(struct state const *, time_t);
|
||||
static bool normalize_overflow32(int_fast32_t *, int *, int);
|
||||
static struct tm *timesub(time_t const *, int_fast32_t, struct state const *,
|
||||
struct tm *);
|
||||
static bool typesequiv(struct state const *, int, int);
|
||||
static bool tzparse(char const *, struct state *, struct state *);
|
||||
static struct tm *localtime_timesub(time_t const *, int_fast32_t,
|
||||
struct state const *, struct tm *);
|
||||
static bool localtime_typesequiv(struct state const *, int, int);
|
||||
static bool localtime_tzparse(char const *, struct state *, struct state *);
|
||||
|
||||
#ifdef ALL_STATE
|
||||
static struct state * lclptr;
|
||||
|
@ -390,8 +391,8 @@ union local_storage {
|
|||
format if DOEXTEND. Use *LSP for temporary storage. Return 0 on
|
||||
success, an errno value on failure. */
|
||||
static int
|
||||
tzloadbody(char const *name, struct state *sp, bool doextend,
|
||||
union local_storage *lsp)
|
||||
localtime_tzloadbody(char const *name, struct state *sp, bool doextend,
|
||||
union local_storage *lsp)
|
||||
{
|
||||
register int i;
|
||||
register int fid;
|
||||
|
@ -628,7 +629,7 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
|
|||
struct state *ts = &lsp->u.st;
|
||||
|
||||
up->buf[nread - 1] = '\0';
|
||||
if (tzparse(&up->buf[1], ts, sp)) {
|
||||
if (localtime_tzparse(&up->buf[1], ts, sp)) {
|
||||
|
||||
/* Attempt to reuse existing abbreviations.
|
||||
Without this, America/Anchorage would be right on
|
||||
|
@ -695,9 +696,9 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
|
|||
int repeattype = sp->types[0];
|
||||
for (i = 1; i < sp->timecnt; ++i)
|
||||
if (sp->ats[i] == repeatat
|
||||
&& typesequiv(sp, sp->types[i], repeattype)) {
|
||||
sp->goback = true;
|
||||
break;
|
||||
&& localtime_typesequiv(sp, sp->types[i], repeattype)) {
|
||||
sp->goback = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (TIME_T_MIN + SECSPERREPEAT <= sp->ats[sp->timecnt - 1]) {
|
||||
|
@ -705,9 +706,9 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
|
|||
int repeattype = sp->types[sp->timecnt - 1];
|
||||
for (i = sp->timecnt - 2; i >= 0; --i)
|
||||
if (sp->ats[i] == repeatat
|
||||
&& typesequiv(sp, sp->types[i], repeattype)) {
|
||||
sp->goahead = true;
|
||||
break;
|
||||
&& localtime_typesequiv(sp, sp->types[i], repeattype)) {
|
||||
sp->goahead = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -770,14 +771,14 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
|
|||
/* Load tz data from the file named NAME into *SP. Read extended
|
||||
format if DOEXTEND. Return 0 on success, an errno value on failure. */
|
||||
static int
|
||||
tzload(char const *name, struct state *sp, bool doextend)
|
||||
localtime_tzload(char const *name, struct state *sp, bool doextend)
|
||||
{
|
||||
#ifdef ALL_STATE
|
||||
union local_storage *lsp = malloc(sizeof *lsp);
|
||||
if (!lsp) {
|
||||
return HAVE_MALLOC_ERRNO ? errno : ENOMEM;
|
||||
} else {
|
||||
int err = tzloadbody(name, sp, doextend, lsp);
|
||||
int err = localtime_tzloadbody(name, sp, doextend, lsp);
|
||||
free(lsp);
|
||||
return err;
|
||||
}
|
||||
|
@ -790,12 +791,12 @@ tzload(char const *name, struct state *sp, bool doextend)
|
|||
for (x = i = 0; i < sizeof(ls); i += 4096) {
|
||||
x += p[i]; /* make sure tzdata doesn't smash the stack */
|
||||
}
|
||||
return tzloadbody(name, sp, doextend, &ls);
|
||||
return localtime_tzloadbody(name, sp, doextend, &ls);
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
typesequiv(const struct state *sp, int a, int b)
|
||||
localtime_typesequiv(const struct state *sp, int a, int b)
|
||||
{
|
||||
register bool result;
|
||||
|
||||
|
@ -1116,7 +1117,7 @@ transtime(const int year, register const struct rule *const rulep,
|
|||
*/
|
||||
|
||||
static bool
|
||||
tzparse(const char *name, struct state *sp, struct state *basep)
|
||||
localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||
{
|
||||
const char * stdname;
|
||||
const char * dstname;
|
||||
|
@ -1157,7 +1158,7 @@ tzparse(const char *name, struct state *sp, struct state *basep)
|
|||
sp->leapcnt = basep->leapcnt;
|
||||
memcpy(sp->lsis, basep->lsis, sp->leapcnt * sizeof *sp->lsis);
|
||||
} else {
|
||||
load_ok = tzload(TZDEFRULES, sp, false) == 0;
|
||||
load_ok = localtime_tzload(TZDEFRULES, sp, false) == 0;
|
||||
if (!load_ok)
|
||||
sp->leapcnt = 0; /* So, we're off a little. */
|
||||
}
|
||||
|
@ -1396,8 +1397,8 @@ tzparse(const char *name, struct state *sp, struct state *basep)
|
|||
static void
|
||||
gmtload(struct state *const sp)
|
||||
{
|
||||
if (tzload(gmt, sp, true) != 0)
|
||||
tzparse("GMT0", sp, NULL);
|
||||
if (localtime_tzload(gmt, sp, true) != 0)
|
||||
localtime_tzparse("GMT0", sp, NULL);
|
||||
}
|
||||
|
||||
/* Initialize *SP to a value appropriate for the TZ setting NAME.
|
||||
|
@ -1419,8 +1420,9 @@ zoneinit(struct state *sp, char const *name)
|
|||
sp->defaulttype = 0;
|
||||
return 0;
|
||||
} else {
|
||||
int err = tzload(name, sp, true);
|
||||
if (err != 0 && name && name[0] != ':' && tzparse(name, sp, NULL))
|
||||
int err = localtime_tzload(name, sp, true);
|
||||
if (err != 0 && name && name[0] != ':' &&
|
||||
localtime_tzparse(name, sp, NULL))
|
||||
err = 0;
|
||||
if (err == 0)
|
||||
scrub_abbrs(sp);
|
||||
|
@ -1429,7 +1431,7 @@ zoneinit(struct state *sp, char const *name)
|
|||
}
|
||||
|
||||
static void
|
||||
tzset_unlocked(void)
|
||||
localtime_tzset_unlocked(void)
|
||||
{
|
||||
char const *name = getenv("TZ");
|
||||
struct state *sp = lclptr;
|
||||
|
@ -1457,12 +1459,12 @@ tzset(void)
|
|||
{
|
||||
if (lock() != 0)
|
||||
return;
|
||||
tzset_unlocked();
|
||||
localtime_tzset_unlocked();
|
||||
unlock();
|
||||
}
|
||||
|
||||
static void
|
||||
gmtcheck(void)
|
||||
localtime_gmtcheck(void)
|
||||
{
|
||||
static bool gmt_is_set;
|
||||
if (lock() != 0)
|
||||
|
@ -1566,7 +1568,7 @@ localsub(struct state const *sp, time_t const *timep, int_fast32_t setname,
|
|||
** t += ttisp->tt_utoff;
|
||||
** timesub(&t, 0L, sp, tmp);
|
||||
*/
|
||||
result = timesub(&t, ttisp->tt_utoff, sp, tmp);
|
||||
result = localtime_timesub(&t, ttisp->tt_utoff, sp, tmp);
|
||||
if (result) {
|
||||
result->tm_isdst = ttisp->tt_isdst;
|
||||
result->tm_zone = (char *) &sp->chars[ttisp->tt_desigidx];
|
||||
|
@ -1585,7 +1587,7 @@ localtime_tzset(time_t const *timep, struct tm *tmp, bool setname)
|
|||
return NULL;
|
||||
}
|
||||
if (setname || !lcl_is_set)
|
||||
tzset_unlocked();
|
||||
localtime_tzset_unlocked();
|
||||
tmp = localsub(lclptr, timep, setname, tmp);
|
||||
unlock();
|
||||
return tmp;
|
||||
|
@ -1613,7 +1615,7 @@ gmtsub(struct state const *sp, time_t const *timep, int_fast32_t offset,
|
|||
{
|
||||
register struct tm * result;
|
||||
|
||||
result = timesub(timep, offset, gmtptr, tmp);
|
||||
result = localtime_timesub(timep, offset, gmtptr, tmp);
|
||||
/*
|
||||
** Could get fancy here and deliver something such as
|
||||
** "+xx" or "-xx" if offset is non-zero,
|
||||
|
@ -1631,7 +1633,7 @@ gmtsub(struct state const *sp, time_t const *timep, int_fast32_t offset,
|
|||
struct tm *
|
||||
gmtime_r(const time_t *timep, struct tm *tmp)
|
||||
{
|
||||
gmtcheck();
|
||||
localtime_gmtcheck();
|
||||
return gmtsub(gmtptr, timep, 0, tmp);
|
||||
}
|
||||
|
||||
|
@ -1661,8 +1663,8 @@ leaps_thru_end_of(time_t y)
|
|||
}
|
||||
|
||||
static struct tm *
|
||||
timesub(const time_t *timep, int_fast32_t offset,
|
||||
const struct state *sp, struct tm *tmp)
|
||||
localtime_timesub(const time_t *timep, int_fast32_t offset,
|
||||
const struct state *sp, struct tm *tmp)
|
||||
{
|
||||
register const struct lsinfo * lp;
|
||||
register time_t tdays;
|
||||
|
@ -1783,11 +1785,16 @@ timesub(const time_t *timep, int_fast32_t offset,
|
|||
** Normalize logic courtesy Paul Eggert.
|
||||
*/
|
||||
|
||||
static bool
|
||||
static inline bool
|
||||
increment_overflow(int *ip, int j)
|
||||
{
|
||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||
int i = *ip;
|
||||
if (__builtin_add_overflow(i, j, &i)) return true;
|
||||
*ip = i;
|
||||
return false;
|
||||
#else
|
||||
register int const i = *ip;
|
||||
|
||||
/*
|
||||
** If i >= 0 there can only be overflow if i + j > INT_MAX
|
||||
** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
|
||||
|
@ -1798,22 +1805,35 @@ increment_overflow(int *ip, int j)
|
|||
return true;
|
||||
*ip += j;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
static inline bool
|
||||
increment_overflow32(int_fast32_t *const lp, int const m)
|
||||
{
|
||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||
int_fast32_t i = *lp;
|
||||
if (__builtin_add_overflow(i, m, &i)) return true;
|
||||
*lp = i;
|
||||
return false;
|
||||
#else
|
||||
register int_fast32_t const l = *lp;
|
||||
|
||||
if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l))
|
||||
return true;
|
||||
*lp += m;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
static inline bool
|
||||
increment_overflow_time(time_t *tp, int_fast32_t j)
|
||||
{
|
||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||
time_t i = *tp;
|
||||
if (__builtin_add_overflow(i, j, &i)) return true;
|
||||
*tp = i;
|
||||
return false;
|
||||
#else
|
||||
/*
|
||||
** This is like
|
||||
** 'if (! (TIME_T_MIN <= *tp + j && *tp + j <= TIME_T_MAX)) ...',
|
||||
|
@ -1825,6 +1845,7 @@ increment_overflow_time(time_t *tp, int_fast32_t j)
|
|||
return true;
|
||||
*tp += j;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -1868,13 +1889,14 @@ tmcomp(register const struct tm *const atmp,
|
|||
}
|
||||
|
||||
static time_t
|
||||
time2sub(struct tm *const tmp,
|
||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||
int_fast32_t, struct tm *),
|
||||
struct state const *sp,
|
||||
const int_fast32_t offset,
|
||||
bool *okayp,
|
||||
bool do_norm_secs)
|
||||
localtime_time2sub(
|
||||
struct tm *const tmp,
|
||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||
int_fast32_t, struct tm *),
|
||||
struct state const *sp,
|
||||
const int_fast32_t offset,
|
||||
bool *okayp,
|
||||
bool do_norm_secs)
|
||||
{
|
||||
register int dir;
|
||||
register int i, j;
|
||||
|
@ -2067,12 +2089,13 @@ label:
|
|||
}
|
||||
|
||||
static time_t
|
||||
time2(struct tm * const tmp,
|
||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||
int_fast32_t, struct tm *),
|
||||
struct state const *sp,
|
||||
const int_fast32_t offset,
|
||||
bool *okayp)
|
||||
localtime_time2(
|
||||
struct tm * const tmp,
|
||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||
int_fast32_t, struct tm *),
|
||||
struct state const *sp,
|
||||
const int_fast32_t offset,
|
||||
bool *okayp)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
|
@ -2081,16 +2104,17 @@ time2(struct tm * const tmp,
|
|||
** (in case tm_sec contains a value associated with a leap second).
|
||||
** If that fails, try with normalization of seconds.
|
||||
*/
|
||||
t = time2sub(tmp, funcp, sp, offset, okayp, false);
|
||||
return *okayp ? t : time2sub(tmp, funcp, sp, offset, okayp, true);
|
||||
t = localtime_time2sub(tmp, funcp, sp, offset, okayp, false);
|
||||
return *okayp ? t : localtime_time2sub(tmp,funcp,sp,offset,okayp,true);
|
||||
}
|
||||
|
||||
static time_t
|
||||
time1(struct tm *const tmp,
|
||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||
int_fast32_t, struct tm *),
|
||||
struct state const *sp,
|
||||
const int_fast32_t offset)
|
||||
localtime_time1(
|
||||
struct tm *const tmp,
|
||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||
int_fast32_t, struct tm *),
|
||||
struct state const *sp,
|
||||
const int_fast32_t offset)
|
||||
{
|
||||
register time_t t;
|
||||
register int samei, otheri;
|
||||
|
@ -2107,7 +2131,7 @@ time1(struct tm *const tmp,
|
|||
}
|
||||
if (tmp->tm_isdst > 1)
|
||||
tmp->tm_isdst = 1;
|
||||
t = time2(tmp, funcp, sp, offset, &okay);
|
||||
t = localtime_time2(tmp, funcp, sp, offset, &okay);
|
||||
if (okay)
|
||||
return t;
|
||||
if (tmp->tm_isdst < 0)
|
||||
|
@ -2146,7 +2170,7 @@ time1(struct tm *const tmp,
|
|||
tmp->tm_sec += (sp->ttis[otheri].tt_utoff
|
||||
- sp->ttis[samei].tt_utoff);
|
||||
tmp->tm_isdst = !tmp->tm_isdst;
|
||||
t = time2(tmp, funcp, sp, offset, &okay);
|
||||
t = localtime_time2(tmp, funcp, sp, offset, &okay);
|
||||
if (okay)
|
||||
return t;
|
||||
tmp->tm_sec -= (sp->ttis[otheri].tt_utoff
|
||||
|
@ -2161,10 +2185,10 @@ static time_t
|
|||
mktime_tzname(struct state *sp, struct tm *tmp, bool setname)
|
||||
{
|
||||
if (sp)
|
||||
return time1(tmp, localsub, sp, setname);
|
||||
return localtime_time1(tmp, localsub, sp, setname);
|
||||
else {
|
||||
gmtcheck();
|
||||
return time1(tmp, gmtsub, gmtptr, 0);
|
||||
localtime_gmtcheck();
|
||||
return localtime_time1(tmp, gmtsub, gmtptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2177,7 +2201,7 @@ mktime(struct tm *tmp)
|
|||
errno = err;
|
||||
return -1;
|
||||
}
|
||||
tzset_unlocked();
|
||||
localtime_tzset_unlocked();
|
||||
t = mktime_tzname(lclptr, tmp, true);
|
||||
unlock();
|
||||
return t;
|
||||
|
|
|
@ -106,7 +106,7 @@ enum warn { IN_NONE, IN_SOME, IN_THIS, IN_ALL };
|
|||
#endif /* !defined YEAR_2000_NAME */
|
||||
|
||||
static char *
|
||||
_add(const char *str, char *pt, const char *ptlim)
|
||||
strftime_add(const char *str, char *pt, const char *ptlim)
|
||||
{
|
||||
while (pt < ptlim && (*pt = *str++) != '\0')
|
||||
++pt;
|
||||
|
@ -114,11 +114,11 @@ _add(const char *str, char *pt, const char *ptlim)
|
|||
}
|
||||
|
||||
static char *
|
||||
_conv(int n, const char *format, char *pt, const char *ptlim)
|
||||
strftime_conv(int n, const char *format, char *pt, const char *ptlim)
|
||||
{
|
||||
char buf[INT_STRLEN_MAXIMUM(int) + 1];
|
||||
(sprintf)(buf, format, n);
|
||||
return _add(buf, pt, ptlim);
|
||||
return strftime_add(buf, pt, ptlim);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -130,8 +130,13 @@ _conv(int n, const char *format, char *pt, const char *ptlim)
|
|||
*/
|
||||
|
||||
static char *
|
||||
_yconv(int a, int b, bool convert_top, bool convert_yy,
|
||||
char *pt, const char *ptlim)
|
||||
strftime_yconv(
|
||||
int a,
|
||||
int b,
|
||||
bool convert_top,
|
||||
bool convert_yy,
|
||||
char *pt,
|
||||
const char *ptlim)
|
||||
{
|
||||
register int lead;
|
||||
register int trail;
|
||||
|
@ -148,17 +153,17 @@ _yconv(int a, int b, bool convert_top, bool convert_yy,
|
|||
}
|
||||
if (convert_top) {
|
||||
if (lead == 0 && trail < 0)
|
||||
pt = _add("-0", pt, ptlim);
|
||||
else pt = _conv(lead, "%02d", pt, ptlim);
|
||||
pt = strftime_add("-0", pt, ptlim);
|
||||
else pt = strftime_conv(lead, "%02d", pt, ptlim);
|
||||
}
|
||||
if (convert_yy)
|
||||
pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
|
||||
pt = strftime_conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
|
||||
return pt;
|
||||
}
|
||||
|
||||
static char *
|
||||
_fmt(const char *format, const struct tm *t, char *pt,
|
||||
const char *ptlim, enum warn *warnp)
|
||||
strftime_fmt(const char *format, const struct tm *t, char *pt,
|
||||
const char *ptlim, enum warn *warnp)
|
||||
{
|
||||
for ( ; *format; ++format) {
|
||||
if (*format == '%') {
|
||||
|
@ -168,27 +173,31 @@ label:
|
|||
--format;
|
||||
break;
|
||||
case 'A':
|
||||
pt = _add((t->tm_wday < 0 ||
|
||||
pt = strftime_add(
|
||||
(t->tm_wday < 0 ||
|
||||
t->tm_wday >= DAYSPERWEEK) ?
|
||||
"?" : Locale->weekday[t->tm_wday],
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'a':
|
||||
pt = _add((t->tm_wday < 0 ||
|
||||
t->tm_wday >= DAYSPERWEEK) ?
|
||||
pt = strftime_add(
|
||||
(t->tm_wday < 0 ||
|
||||
t->tm_wday >= DAYSPERWEEK) ?
|
||||
"?" : Locale->wday[t->tm_wday],
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'B':
|
||||
pt = _add((t->tm_mon < 0 ||
|
||||
t->tm_mon >= MONSPERYEAR) ?
|
||||
pt = strftime_add(
|
||||
(t->tm_mon < 0 ||
|
||||
t->tm_mon >= MONSPERYEAR) ?
|
||||
"?" : Locale->month[t->tm_mon],
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'b':
|
||||
case 'h':
|
||||
pt = _add((t->tm_mon < 0 ||
|
||||
t->tm_mon >= MONSPERYEAR) ?
|
||||
pt = strftime_add(
|
||||
(t->tm_mon < 0 ||
|
||||
t->tm_mon >= MONSPERYEAR) ?
|
||||
"?" : Locale->mon[t->tm_mon],
|
||||
pt, ptlim);
|
||||
continue;
|
||||
|
@ -200,14 +209,14 @@ label:
|
|||
** something completely different.
|
||||
** (ado, 1993-05-24)
|
||||
*/
|
||||
pt = _yconv(t->tm_year, TM_YEAR_BASE,
|
||||
true, false, pt, ptlim);
|
||||
pt = strftime_yconv(t->tm_year, TM_YEAR_BASE,
|
||||
true, false, pt, ptlim);
|
||||
continue;
|
||||
case 'c':
|
||||
{
|
||||
enum warn warn2 = IN_SOME;
|
||||
|
||||
pt = _fmt(Locale->c_fmt, t, pt, ptlim, &warn2);
|
||||
pt = strftime_fmt(Locale->c_fmt, t, pt, ptlim, &warn2);
|
||||
if (warn2 == IN_ALL)
|
||||
warn2 = IN_THIS;
|
||||
if (warn2 > *warnp)
|
||||
|
@ -215,10 +224,10 @@ label:
|
|||
}
|
||||
continue;
|
||||
case 'D':
|
||||
pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt("%m/%d/%y", t, pt, ptlim, warnp);
|
||||
continue;
|
||||
case 'd':
|
||||
pt = _conv(t->tm_mday, "%02d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_mday, "%02d", pt, ptlim);
|
||||
continue;
|
||||
case 'E':
|
||||
case 'O':
|
||||
|
@ -233,21 +242,21 @@ label:
|
|||
*/
|
||||
goto label;
|
||||
case 'e':
|
||||
pt = _conv(t->tm_mday, "%2d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_mday, "%2d", pt, ptlim);
|
||||
continue;
|
||||
case 'F':
|
||||
pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt("%Y-%m-%d", t, pt, ptlim, warnp);
|
||||
continue;
|
||||
case 'H':
|
||||
pt = _conv(t->tm_hour, "%02d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_hour, "%02d", pt, ptlim);
|
||||
continue;
|
||||
case 'I':
|
||||
pt = _conv((t->tm_hour % 12) ?
|
||||
(t->tm_hour % 12) : 12,
|
||||
"%02d", pt, ptlim);
|
||||
pt = strftime_conv((t->tm_hour % 12) ?
|
||||
(t->tm_hour % 12) : 12,
|
||||
"%02d", pt, ptlim);
|
||||
continue;
|
||||
case 'j':
|
||||
pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_yday + 1, "%03d", pt, ptlim);
|
||||
continue;
|
||||
case 'k':
|
||||
/*
|
||||
|
@ -260,14 +269,15 @@ label:
|
|||
** "%l" have been swapped.
|
||||
** (ado, 1993-05-24)
|
||||
*/
|
||||
pt = _conv(t->tm_hour, "%2d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_hour, "%2d",
|
||||
pt, ptlim);
|
||||
continue;
|
||||
#ifdef KITCHEN_SINK
|
||||
case 'K':
|
||||
/*
|
||||
** After all this time, still unclaimed!
|
||||
*/
|
||||
pt = _add("kitchen sink", pt, ptlim);
|
||||
pt = strftime_add("kitchen sink", pt, ptlim);
|
||||
continue;
|
||||
#endif /* defined KITCHEN_SINK */
|
||||
case 'l':
|
||||
|
@ -280,33 +290,38 @@ label:
|
|||
** "%l" have been swapped.
|
||||
** (ado, 1993-05-24)
|
||||
*/
|
||||
pt = _conv((t->tm_hour % 12) ?
|
||||
(t->tm_hour % 12) : 12,
|
||||
"%2d", pt, ptlim);
|
||||
pt = strftime_conv((t->tm_hour % 12) ?
|
||||
(t->tm_hour % 12) : 12,
|
||||
"%2d", pt, ptlim);
|
||||
continue;
|
||||
case 'M':
|
||||
pt = _conv(t->tm_min, "%02d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_min, "%02d",
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'm':
|
||||
pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_mon + 1, "%02d",
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'n':
|
||||
pt = _add("\n", pt, ptlim);
|
||||
pt = strftime_add("\n", pt, ptlim);
|
||||
continue;
|
||||
case 'p':
|
||||
pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
|
||||
pt = strftime_add(
|
||||
(t->tm_hour >= (HOURSPERDAY / 2)) ?
|
||||
Locale->pm :
|
||||
Locale->am,
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'R':
|
||||
pt = _fmt("%H:%M", t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt("%H:%M", t, pt, ptlim, warnp);
|
||||
continue;
|
||||
case 'r':
|
||||
pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt("%I:%M:%S %p", t, pt,
|
||||
ptlim, warnp);
|
||||
continue;
|
||||
case 'S':
|
||||
pt = _conv(t->tm_sec, "%02d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_sec, "%02d", pt,
|
||||
ptlim);
|
||||
continue;
|
||||
case 's':
|
||||
{
|
||||
|
@ -338,19 +353,19 @@ label:
|
|||
uintmax_t n = mkt;
|
||||
(sprintf)(buf, "%"PRIuMAX, n);
|
||||
}
|
||||
pt = _add(buf, pt, ptlim);
|
||||
pt = strftime_add(buf, pt, ptlim);
|
||||
}
|
||||
continue;
|
||||
case 'T':
|
||||
pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt("%H:%M:%S", t, pt, ptlim, warnp);
|
||||
continue;
|
||||
case 't':
|
||||
pt = _add("\t", pt, ptlim);
|
||||
pt = strftime_add("\t", pt, ptlim);
|
||||
continue;
|
||||
case 'U':
|
||||
pt = _conv((t->tm_yday + DAYSPERWEEK -
|
||||
t->tm_wday) / DAYSPERWEEK,
|
||||
"%02d", pt, ptlim);
|
||||
pt = strftime_conv((t->tm_yday + DAYSPERWEEK -
|
||||
t->tm_wday) / DAYSPERWEEK,
|
||||
"%02d", pt, ptlim);
|
||||
continue;
|
||||
case 'u':
|
||||
/*
|
||||
|
@ -359,9 +374,9 @@ label:
|
|||
** [1 (Monday) - 7]"
|
||||
** (ado, 1993-05-24)
|
||||
*/
|
||||
pt = _conv((t->tm_wday == 0) ?
|
||||
DAYSPERWEEK : t->tm_wday,
|
||||
"%d", pt, ptlim);
|
||||
pt = strftime_conv((t->tm_wday == 0) ?
|
||||
DAYSPERWEEK : t->tm_wday,
|
||||
"%d", pt, ptlim);
|
||||
continue;
|
||||
case 'V': /* ISO 8601 week number */
|
||||
case 'G': /* ISO 8601 year (four digits) */
|
||||
|
@ -434,16 +449,16 @@ label:
|
|||
DAYSPERNYEAR;
|
||||
}
|
||||
if (*format == 'V')
|
||||
pt = _conv(w, "%02d",
|
||||
pt, ptlim);
|
||||
pt = strftime_conv(w, "%02d",
|
||||
pt, ptlim);
|
||||
else if (*format == 'g') {
|
||||
*warnp = IN_ALL;
|
||||
pt = _yconv(year, base,
|
||||
false, true,
|
||||
pt, ptlim);
|
||||
} else pt = _yconv(year, base,
|
||||
true, true,
|
||||
pt, ptlim);
|
||||
pt = strftime_yconv(year, base,
|
||||
false, true,
|
||||
pt, ptlim);
|
||||
} else pt = strftime_yconv(year, base,
|
||||
true, true,
|
||||
pt, ptlim);
|
||||
}
|
||||
continue;
|
||||
case 'v':
|
||||
|
@ -452,26 +467,27 @@ label:
|
|||
** "date as dd-bbb-YYYY"
|
||||
** (ado, 1993-05-24)
|
||||
*/
|
||||
pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt("%e-%b-%Y", t, pt, ptlim, warnp);
|
||||
continue;
|
||||
case 'W':
|
||||
pt = _conv((t->tm_yday + DAYSPERWEEK -
|
||||
(t->tm_wday ?
|
||||
(t->tm_wday - 1) :
|
||||
(DAYSPERWEEK - 1))) / DAYSPERWEEK,
|
||||
pt = strftime_conv(
|
||||
(t->tm_yday + DAYSPERWEEK -
|
||||
(t->tm_wday ?
|
||||
(t->tm_wday - 1) :
|
||||
(DAYSPERWEEK - 1))) / DAYSPERWEEK,
|
||||
"%02d", pt, ptlim);
|
||||
continue;
|
||||
case 'w':
|
||||
pt = _conv(t->tm_wday, "%d", pt, ptlim);
|
||||
pt = strftime_conv(t->tm_wday, "%d", pt, ptlim);
|
||||
continue;
|
||||
case 'X':
|
||||
pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
|
||||
pt = strftime_fmt(Locale->X_fmt, t, pt, ptlim, warnp);
|
||||
continue;
|
||||
case 'x':
|
||||
{
|
||||
enum warn warn2 = IN_SOME;
|
||||
|
||||
pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
|
||||
pt = strftime_fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
|
||||
if (warn2 == IN_ALL)
|
||||
warn2 = IN_THIS;
|
||||
if (warn2 > *warnp)
|
||||
|
@ -480,17 +496,17 @@ label:
|
|||
continue;
|
||||
case 'y':
|
||||
*warnp = IN_ALL;
|
||||
pt = _yconv(t->tm_year, TM_YEAR_BASE,
|
||||
false, true,
|
||||
pt, ptlim);
|
||||
pt = strftime_yconv(t->tm_year, TM_YEAR_BASE,
|
||||
false, true,
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'Y':
|
||||
pt = _yconv(t->tm_year, TM_YEAR_BASE,
|
||||
true, true,
|
||||
pt, ptlim);
|
||||
pt = strftime_yconv(t->tm_year, TM_YEAR_BASE,
|
||||
true, true,
|
||||
pt, ptlim);
|
||||
continue;
|
||||
case 'Z':
|
||||
pt = _add(t->tm_zone, pt, ptlim);
|
||||
pt = strftime_add(t->tm_zone, pt, ptlim);
|
||||
/*
|
||||
** C99 and later say that %Z must be
|
||||
** replaced by the empty string if the
|
||||
|
@ -513,16 +529,16 @@ label:
|
|||
sign = "-";
|
||||
diff = -diff;
|
||||
} else sign = "+";
|
||||
pt = _add(sign, pt, ptlim);
|
||||
pt = strftime_add(sign, pt, ptlim);
|
||||
diff /= SECSPERMIN;
|
||||
diff = (diff / MINSPERHOUR) * 100 +
|
||||
(diff % MINSPERHOUR);
|
||||
pt = _conv(diff, "%04d", pt, ptlim);
|
||||
pt = strftime_conv(diff, "%04d", pt, ptlim);
|
||||
}
|
||||
continue;
|
||||
case '+':
|
||||
pt = _fmt(Locale->date_fmt, t, pt, ptlim,
|
||||
warnp);
|
||||
pt = strftime_fmt(Locale->date_fmt, t, pt,
|
||||
ptlim, warnp);
|
||||
continue;
|
||||
case '%':
|
||||
/*
|
||||
|
@ -562,7 +578,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *t)
|
|||
enum warn warn = IN_NONE;
|
||||
|
||||
tzset();
|
||||
p = _fmt(format, t, s, s + maxsize, &warn);
|
||||
p = strftime_fmt(format, t, s, s + maxsize, &warn);
|
||||
if (!p) {
|
||||
errno = EOVERFLOW;
|
||||
return 0;
|
||||
|
|
|
@ -61,8 +61,7 @@ o/$(MODE)/libc/time/strftime.o: \
|
|||
OVERRIDE_CFLAGS += \
|
||||
-fno-jump-tables
|
||||
|
||||
o/$(MODE)/libc/time/localtime.o \
|
||||
o/$(MODE)/libc/time/strftime.o: \
|
||||
o/$(MODE)/libc/time/localtime.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-fdata-sections \
|
||||
-ffunction-sections
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue