char* asctime(Tm *t) { char *ncp; static char cbuf[30]; strcpy(cbuf, "Thu Jan 01 00:00:00 GMT 1970\n"); ncp = &"SunMonTueWedThuFriSat"[t->wday*3]; cbuf[0] = *ncp++; cbuf[1] = *ncp++; cbuf[2] = *ncp; ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[t->mon*3]; cbuf[4] = *ncp++; cbuf[5] = *ncp++; cbuf[6] = *ncp; ct_numb(cbuf+8, t->mday); ct_numb(cbuf+11, t->hour+100); ct_numb(cbuf+14, t->min+100); ct_numb(cbuf+17, t->sec+100); ncp = t->zone; cbuf[20] = *ncp++; cbuf[21] = *ncp++; cbuf[22] = *ncp; if(t->year >= 100) { cbuf[24] = '2'; cbuf[25] = '0'; } ct_numb(cbuf+26, t->year+100); return cbuf; }
int Tfmt(Fmt *f1) { char s[30]; char *cp; long t; Tm tm; t = va_arg(f1->args, long); if(t == 0) return fmtstrcpy(f1, "The Epoch"); klocaltime(t, &tm); strcpy(s, "Day Mon 00 00:00:00 1900"); cp = &"SunMonTueWedThuFriSat"[tm.wday*3]; s[0] = cp[0]; s[1] = cp[1]; s[2] = cp[2]; cp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[tm.mon*3]; s[4] = cp[0]; s[5] = cp[1]; s[6] = cp[2]; ct_numb(s+8, tm.mday); ct_numb(s+11, tm.hour+100); ct_numb(s+14, tm.min+100); ct_numb(s+17, tm.sec+100); if(tm.year >= 100) { s[20] = '2'; s[21] = '0'; } ct_numb(s+22, tm.year+100); return fmtstrcpy(f1, s); }
char* asctime_r(const struct tm *t, char *buf) { char *ncp; strcpy(buf, "Thu Jan 01 00:00:00 1970\n"); ncp = &"SunMonTueWedThuFriSat"[t->tm_wday*3]; buf[0] = *ncp++; buf[1] = *ncp++; buf[2] = *ncp; ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[t->tm_mon*3]; buf[4] = *ncp++; buf[5] = *ncp++; buf[6] = *ncp; ct_numb(buf+8, t->tm_mday); ct_numb(buf+11, t->tm_hour+100); ct_numb(buf+14, t->tm_min+100); ct_numb(buf+17, t->tm_sec+100); if(t->tm_year >= 100) { buf[20] = '2'; buf[21] = '0'; } ct_numb(buf+22, t->tm_year+100); return buf; }
char * asctime(const struct tm *t) { char *cp; const char *ncp; const int *tp; const char *Date = "Day Mon 00 00:00:00 1900\n"; const char *Day = "SunMonTueWedThuFriSat"; const char *Month = "JanFebMarAprMayJunJulAugSepOctNovDec"; static char cbuf[CBUFSIZ]; cp = cbuf; for (ncp = Date; *cp++ = *ncp++; /* */); ncp = Day + (3 * t->tm_wday); cp = cbuf; *cp++ = *ncp++; *cp++ = *ncp++; *cp++ = *ncp++; cp++; tp = &t->tm_mon; ncp = Month + ((*tp) * 3); *cp++ = *ncp++; *cp++ = *ncp++; *cp++ = *ncp++; cp = ct_numb(cp, *--tp); cp = ct_numb(cp, *--tp + 100); cp = ct_numb(cp, *--tp + 100); --tp; cp = ct_numb(cp, *tp + 100); if (t->tm_year < 100) { /* Common case: "19" already in buffer */ cp += 2; } else if (t->tm_year < 8100) { cp = ct_numb(cp, (1900 + t->tm_year) / 100); cp--; } else { /* Only 4-digit years are supported */ errno = EOVERFLOW; return (NULL); } (void) ct_numb(cp, t->tm_year + 100); return (cbuf); }