Advertisement
Guest User

Untitled

a guest
Aug 12th, 2019
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None
  1. #include <time.h>
  2. #include <stdio.h>
  3.  
  4. #define ID_TIME_T time_t
  5.  
  6. int DST_MODE = 0xDEADBEEF;
  7.  
  8. long Sys_DosToUnixTime( unsigned long dostime ) {
  9.     ID_TIME_T unix_time = 0;
  10.     unsigned int sec, min, hour, day, mon, year;
  11.     struct tm dostm;
  12.  
  13.     // break dos time down into its sec, min, hour components
  14.     sec = (dostime & 0x1F) * 2;
  15.     min = (dostime & 0x7E0) >> 5;
  16.     hour = (dostime & 0xF800)  >> 11;
  17.  
  18.     // temporarily remove time component
  19.     year = dostime >> 16;
  20.    
  21.     // break dos date down into its day, month, year components
  22.     day = year & 0x1F;
  23.     mon = (year & 0x1E0) >> 5;
  24.     year = (year >> 9) + 1980;
  25.  
  26.     printf("Y%u M%u D%u  h%u m%u s%u\n", year, mon, day, hour, min, sec);
  27.     if (sec <= 60 && min <= 59 && hour <= 23 && day >= 1 && day <= 31 && mon >= 1 && mon <= 12 && year <= 2107) {
  28.         dostm.tm_sec = sec;
  29.         dostm.tm_min = min;
  30.         dostm.tm_hour = hour;
  31.         dostm.tm_mday = day;
  32.         dostm.tm_mon = mon - 1;
  33.         dostm.tm_year = year - 1900;
  34.  
  35.         if (DST_MODE != 0xDEADBEEF)
  36.             dostm.tm_isdst = DST_MODE;
  37.        
  38.         printf("Y%u M%u D%u  h%u m%u s%u\n", dostm.tm_year, dostm.tm_mon, dostm.tm_mday, dostm.tm_hour, dostm.tm_min, dostm.tm_sec);
  39.         unix_time = mktime(&dostm);
  40.     }
  41.  
  42.     return (long) unix_time;
  43. }
  44.  
  45. int main() {
  46.     printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
  47.     DST_MODE = -1;
  48.     printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
  49.     DST_MODE = 0;
  50.     printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
  51.     DST_MODE = 1;
  52.     printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
  53.     return 0;
  54. }
Advertisement
RAW Paste Data Copied
Advertisement