Blob
1 #include <u.h>2 #include <libc.h>4 static5 void6 ct_numb(char *cp, int n)7 {9 cp[0] = ' ';10 if(n >= 10)11 cp[0] = (n/10)%10 + '0';12 cp[1] = n%10 + '0';13 }15 char*16 asctime(Tm *t)17 {18 int i;19 char *ncp;20 static char cbuf[30];22 strcpy(cbuf, "Thu Jan 01 00:00:00 GMT 1970\n");23 ncp = &"SunMonTueWedThuFriSat"[t->wday*3];24 cbuf[0] = *ncp++;25 cbuf[1] = *ncp++;26 cbuf[2] = *ncp;27 ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[t->mon*3];28 cbuf[4] = *ncp++;29 cbuf[5] = *ncp++;30 cbuf[6] = *ncp;31 ct_numb(cbuf+8, t->mday);32 ct_numb(cbuf+11, t->hour+100);33 ct_numb(cbuf+14, t->min+100);34 ct_numb(cbuf+17, t->sec+100);35 ncp = t->zone;36 for(i=0; i<3; i++)37 if(ncp[i] == 0)38 break;39 for(; i<3; i++)40 ncp[i] = '?';41 ncp = t->zone;42 cbuf[20] = *ncp++;43 cbuf[21] = *ncp++;44 cbuf[22] = *ncp;45 if(t->year >= 100) {46 cbuf[24] = '2';47 cbuf[25] = '0';48 }49 ct_numb(cbuf+26, t->year+100);50 return cbuf;51 }53 char*54 ctime(long t)55 {56 return asctime(localtime(t));57 }