localtime.c (483B)
1 #include <string.h> 2 #include <time.h> 3 4 #include "../libc.h" 5 #undef localtime 6 7 struct tm * 8 localtime(const time_t *timep) 9 { 10 time_t t; 11 int dst; 12 long off; 13 char *name; 14 struct tm *tm; 15 16 t = *timep; 17 tm = gmtime(&t); 18 _tzset(); 19 20 if (_daylight && _isdst(tm)) { 21 dst = 1; 22 off = _dstzone; 23 name = _tzname[1]; 24 } else { 25 dst = 0; 26 off = _timezone; 27 name = _tzname[0]; 28 } 29 30 t -= off; 31 tm = gmtime(&t); 32 tm->tm_zone = name; 33 tm->tm_isdst = dst; 34 tm->tm_gmtoff = off; 35 36 return tm; 37 }