MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / date_dos2unix

Function date_dos2unix

src/common.c:362–394  ·  view source on GitHub ↗

@ @ requires -14*3600 <= secwest <= 12*3600; @ requires f_time <= 0xffffffff; @ requires f_date <= 0xffffffff; @ terminates \true; @ assigns \nothing; @*/

Source from the content-addressed store, hash-verified

360 @ assigns \nothing;
361 @*/
362time_t date_dos2unix(const unsigned short f_time, const unsigned short f_date)
363{
364 static const unsigned int days_in_year[] = { 0, 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0 };
365 /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */
366
367 unsigned long int day,leap_day,month,year,days;
368 unsigned long int secs;
369 year = f_date >> 9;
370 /*@ assert 0 <= year <= 127; */
371 month = td_max(1, (f_date >> 5) & 0xf);
372 /*@ assert 1 <= month <= 15; */
373 day = td_max(1, f_date & 0x1f) - 1;
374 /*@ assert 0 <= day <= 30; */
375 leap_day = _date_get_leap_day(year, month);
376 /*@ assert 0 <= leap_day <= 32; */
377 days = days_in_year[month];
378 /*@ assert 0 <= days <= 334; */
379 days = _date_get_days(days, year, leap_day, day);
380 /*@ assert 0 <= days <= 334 + 127 * 365 + 32 + 30 + DAYS_DELTA; */
381 secs = _date_get_seconds(f_time &0x1f);
382 /*@ assert secs <= 62; */
383 secs += _date_min_to_seconds((f_time >> 5) & 0x3f);
384 /*@ assert secs <= 0x3f * SECS_PER_MIN + 62; */
385 secs += _date_hours_to_seconds(f_time >> 11);
386 /*@ assert secs <= 0x3f * SECS_PER_HOUR + 0x3f * SECS_PER_MIN + 62; */
387 secs += days * SECS_PER_DAY;
388 /*@ assert secs <= (334 + 127 * 365 + 32 + 30 + DAYS_DELTA)* SECS_PER_DAY + 0x3f * SECS_PER_HOUR + 0x3f * SECS_PER_MIN + 62; */
389#if defined(__FRAMAC__)
390 return secs;
391#else
392 return secs+secwest;
393#endif
394}
395
396void set_secwest(void)
397{

Callers 4

header_check_dirFunction · 0.85
dir_exfat_auxFunction · 0.85
dir_fat_auxFunction · 0.85
zip_parse_file_entryFunction · 0.85

Calls 5

_date_get_leap_dayFunction · 0.85
_date_get_daysFunction · 0.85
_date_get_secondsFunction · 0.85
_date_min_to_secondsFunction · 0.85
_date_hours_to_secondsFunction · 0.85

Tested by

no test coverage detected