Subversion Repositories Kolibri OS

Rev

Rev 9094 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <time.h>
  2. #include <sys/ksys.h>
  3.  
  4. time_t time(time_t *timer){
  5.     static struct tm __buffertime;
  6.     int kos_date, kos_time;
  7.     kos_date = _ksys_get_date().val;
  8.     kos_time = _ksys_get_time().val;
  9.    
  10.     int bcd_day = (kos_date >> 16);
  11.     int bcd_mon = ((kos_date & 0xFF00) >> 8);
  12.     int bcd_year = (kos_date & 0xFF);
  13.     __buffertime.tm_mday = ((bcd_day & 0xF0)>>4)*10 + (bcd_day & 0x0F);
  14.     __buffertime.tm_mon = ((bcd_mon & 0xF0)>>4)*10 + (bcd_mon & 0x0F) - 1;
  15.     __buffertime.tm_year = ((bcd_year & 0xF0)>>4)*10 + (bcd_year & 0x0F) + 100;
  16.    
  17.     __buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */
  18.    
  19.     int bcd_sec = (kos_time >> 16);
  20.     int bcd_min = ((kos_time & 0xFF00) >> 8);
  21.     int bcd_hour = (kos_time & 0xFF);
  22.  
  23.     __buffertime.tm_sec = ((bcd_sec & 0xF0)>>4)*10 + (bcd_sec & 0x0F);
  24.     __buffertime.tm_min = ((bcd_min & 0xF0)>>4)*10 + (bcd_min & 0x0F);
  25.     __buffertime.tm_hour = ((bcd_hour & 0xF0)>>4)*10 + (bcd_hour & 0x0F);
  26.    
  27.     time_t ret = mktime(&__buffertime);
  28.     if(timer){
  29.         *timer=ret;
  30.     }
  31.     return ret;
  32. }
  33.