scc

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

gmtime.c (661B)


      1 #include <time.h>
      2 
      3 #include "../libc.h"
      4 
      5 #undef gmtime
      6 
      7 struct tm *
      8 gmtime(const time_t *tim)
      9 {
     10 	static struct tm tm;
     11 	time_t day;
     12 	int i;
     13 
     14 	tm.tm_sec = *tim % SECDAY;
     15 	tm.tm_min = tm.tm_sec / 60;
     16 	tm.tm_sec %= 60;
     17 	tm.tm_hour = tm.tm_min / 60;
     18 	tm.tm_min %= 60;
     19 	day = *tim / SECDAY;
     20 
     21 	tm.tm_wday = (day + THU) % 7; /* 1/1/1970 was Thursday */
     22 
     23 	for (i = EPOCH; day >= _daysyear(i); ++i)
     24 		day -= _daysyear(i);
     25 	tm.tm_year = i - 1900;
     26 	tm.tm_yday = day;
     27 
     28 	_daysmon[FEB] = FEBDAYS(i);
     29 	for (i = JAN; day >= _daysmon[i]; i++)
     30 		day -= _daysmon[i];
     31 	tm.tm_mon = i;
     32 	tm.tm_mday = day + 1;
     33 
     34 	tm.tm_isdst = 0;
     35 	tm.tm_zone = "GMT";
     36 	tm.tm_gmtoff = 0;
     37 
     38 	return &tm;
     39 }