11 long get_long(char *&ptr)
14 for(unsigned i=0; i<4; ++i)
15 result = (result<<8)+static_cast<unsigned char >(*ptr++);
25 TimeZone TimeZone::platform_get_local_timezone()
27 int fd = open("/etc/localtime", O_RDONLY);
31 int len = read(fd, hdr, sizeof(hdr));
34 if(len==44 && hdr[0]=='T' && hdr[1]=='Z' && hdr[2]=='i' && hdr[3]=='f')
37 long isgmtcnt = get_long(ptr);
38 long isstdcnt = get_long(ptr);
39 long leapcnt = get_long(ptr);
40 long timecnt = get_long(ptr);
41 long typecnt = get_long(ptr);
42 long charcnt = get_long(ptr);
43 int size = timecnt*5+typecnt*6+isgmtcnt+isstdcnt+leapcnt*8+charcnt;
44 char *buf = new char[size];
45 len = read(fd, buf, size);
50 time_t cur_time = Msp::Time::now().to_unixtime();
51 for(int i=0; i<timecnt; ++i)
52 if(get_long(ptr)<=cur_time)
60 for(int i=0; i<typecnt; ++i)
62 if((index>=0 && i==index) || (index<0 && !ptr[4] && gmtoff==-1))
64 gmtoff = get_long(ptr);
79 return TimeZone(gmtoff/60, name);