Home
       localtime.c - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
       localtime.c (892B)
       ---
            1 #include <string.h>
            2 #include <time.h>
            3 
            4 #include "../libc.h"
            5 #undef localtime
            6 
            7 static time_t
            8 gmtoff(char *tz)
            9 {
           10         struct tzone *t;
           11 
           12         for (t = tzones; t->name; t++) {
           13                 if (!strcmp(t->name, tz))
           14                         return t->gmtoff;
           15         }
           16         return 0;
           17 }
           18 
           19 struct tm *
           20 localtime(const time_t *timep)
           21 {
           22         struct tm *tm;
           23         time_t t;
           24         int yday;
           25         static int first = 1;
           26 
           27         t = *timep;
           28         tm = gmtime(&t);
           29         yday = tm->tm_yday;
           30 
           31         if (first) {
           32                 _tzset();
           33                 if (_tzstdoff == -1)
           34                         _tzstdoff = gmtoff(_tzname[0]);
           35                 if (_tzdstoff == -1)
           36                         _tzdstoff = gmtoff(_tzname[1]);
           37         }
           38         first = 0;
           39 
           40         tm->tm_gmtoff = _tzstdoff;
           41         tm->tm_zone = _tzname[0];
           42         tm->tm_isdst = 0;
           43 
           44         if (_tzjulian && yday+1 < 60 || FEBDAYS(tm->tm_year) < 29)
           45                 yday++;
           46 
           47         if (yday >= _tzstart && yday <= _tzend && tm->tm_hour >= 2) {
           48                 tm->tm_gmtoff = _tzdstoff;
           49                 tm->tm_zone = _tzname[1];
           50                 tm->tm_isdst = 1;
           51         }
           52 
           53         t += tm->tm_gmtoff;
           54         tm = gmtime(&t);
           55 
           56         return tm;
           57 }