scc

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

gmtime.c (679B)


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