scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

localtime.c (472B)


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