From 7562eef4c1e4e7ef1200db567f3c8b3203689b9a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 19 Oct 2020 21:34:56 +1100 Subject: [PATCH] AP_Filesystem: use mktime from AP_RTC --- .../AP_Filesystem/AP_Filesystem_FATFS.cpp | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp b/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp index 366c9b6b86..87e8f5170c 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #if HAVE_FILESYSTEM_SUPPORT && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS @@ -540,48 +541,6 @@ off_t AP_Filesystem_FATFS::lseek(int fileno, off_t position, int whence) return fh->fptr; } -/* - mktime replacement from Samba - */ -static time_t replace_mktime(const struct tm *t) -{ - time_t epoch = 0; - int n; - int mon [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, y, m, i; - const unsigned MINUTE = 60; - const unsigned HOUR = 60*MINUTE; - const unsigned DAY = 24*HOUR; - const unsigned YEAR = 365*DAY; - - if (t->tm_year < 70) { - return (time_t)-1; - } - - n = t->tm_year + 1900 - 1; - epoch = (t->tm_year - 70) * YEAR + - ((n / 4 - n / 100 + n / 400) - (1969 / 4 - 1969 / 100 + 1969 / 400)) * DAY; - - y = t->tm_year + 1900; - m = 0; - - for (i = 0; i < t->tm_mon; i++) { - epoch += mon [m] * DAY; - if (m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) { - epoch += DAY; - } - - if (++m > 11) { - m = 0; - y++; - } - } - - epoch += (t->tm_mday - 1) * DAY; - epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec; - - return epoch; -} - static time_t fat_time_to_unix(uint16_t date, uint16_t time) { struct tm tp; @@ -595,7 +554,7 @@ static time_t fat_time_to_unix(uint16_t date, uint16_t time) tp.tm_mday = (date & 0x1f); tp.tm_mon = ((date >> 5) & 0x0f) - 1; tp.tm_year = ((date >> 9) & 0x7f) + 80; - unix = replace_mktime( &tp ); + unix = AP::rtc().mktime(&tp); return unix; }