Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdio.h>
- #define ID_TIME_T time_t
- int DST_MODE = 0xDEADBEEF;
- long Sys_DosToUnixTime( unsigned long dostime ) {
- ID_TIME_T unix_time = 0;
- unsigned int sec, min, hour, day, mon, year;
- struct tm dostm;
- // break dos time down into its sec, min, hour components
- sec = (dostime & 0x1F) * 2;
- min = (dostime & 0x7E0) >> 5;
- hour = (dostime & 0xF800) >> 11;
- // temporarily remove time component
- year = dostime >> 16;
- // break dos date down into its day, month, year components
- day = year & 0x1F;
- mon = (year & 0x1E0) >> 5;
- year = (year >> 9) + 1980;
- printf("Y%u M%u D%u h%u m%u s%u\n", year, mon, day, hour, min, sec);
- if (sec <= 60 && min <= 59 && hour <= 23 && day >= 1 && day <= 31 && mon >= 1 && mon <= 12 && year <= 2107) {
- dostm.tm_sec = sec;
- dostm.tm_min = min;
- dostm.tm_hour = hour;
- dostm.tm_mday = day;
- dostm.tm_mon = mon - 1;
- dostm.tm_year = year - 1900;
- if (DST_MODE != 0xDEADBEEF)
- dostm.tm_isdst = DST_MODE;
- 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);
- unix_time = mktime(&dostm);
- }
- return (long) unix_time;
- }
- int main() {
- printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
- DST_MODE = -1;
- printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
- DST_MODE = 0;
- printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
- DST_MODE = 1;
- printf("%ld\n", Sys_DosToUnixTime(0x4499A9C0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement