mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
Random minor fixes (#757)
* Fix incorrect/questionable assert() usage Originally reported by https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2159000700, but also includes a bunch of other fixes. * Fix some `printf` warnings Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2160310550 * Remove useless check It is never passed thanks to `if (num_in < 1) {...; return}` before Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2154840804 * Add missing header guard, rename other to avoid conflicts Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2163210746 * Make DSi_SDDevice destructor virtual Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2158670642 * Use thread-safe localtime_r, assign `time` result directly Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2154840805 * Fix MinGW build It needs _POSIX_THREAD_SAFE_FUNCTIONS to export `localtime_r`
This commit is contained in:
37
src/RTC.cpp
37
src/RTC.cpp
@ -16,6 +16,9 @@
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
// Required by MinGW to enable localtime_r in time.h
|
||||
#define _POSIX_THREAD_SAFE_FUNCTIONS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@ -125,31 +128,29 @@ void ByteIn(u8 val)
|
||||
|
||||
case 0x20:
|
||||
{
|
||||
time_t timestamp;
|
||||
struct tm* timedata;
|
||||
time(×tamp);
|
||||
timedata = localtime(×tamp);
|
||||
time_t timestamp = time(NULL);
|
||||
struct tm timedata;
|
||||
localtime_r(×tamp, &timedata);
|
||||
|
||||
Output[0] = BCD(timedata->tm_year - 100);
|
||||
Output[1] = BCD(timedata->tm_mon + 1);
|
||||
Output[2] = BCD(timedata->tm_mday);
|
||||
Output[3] = BCD(timedata->tm_wday);
|
||||
Output[4] = BCD(timedata->tm_hour);
|
||||
Output[5] = BCD(timedata->tm_min);
|
||||
Output[6] = BCD(timedata->tm_sec);
|
||||
Output[0] = BCD(timedata.tm_year - 100);
|
||||
Output[1] = BCD(timedata.tm_mon + 1);
|
||||
Output[2] = BCD(timedata.tm_mday);
|
||||
Output[3] = BCD(timedata.tm_wday);
|
||||
Output[4] = BCD(timedata.tm_hour);
|
||||
Output[5] = BCD(timedata.tm_min);
|
||||
Output[6] = BCD(timedata.tm_sec);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x60:
|
||||
{
|
||||
time_t timestamp;
|
||||
struct tm* timedata;
|
||||
time(×tamp);
|
||||
timedata = localtime(×tamp);
|
||||
time_t timestamp = time(NULL);
|
||||
struct tm timedata;
|
||||
localtime_r(×tamp, &timedata);
|
||||
|
||||
Output[0] = BCD(timedata->tm_hour);
|
||||
Output[1] = BCD(timedata->tm_min);
|
||||
Output[2] = BCD(timedata->tm_sec);
|
||||
Output[0] = BCD(timedata.tm_hour);
|
||||
Output[1] = BCD(timedata.tm_min);
|
||||
Output[2] = BCD(timedata.tm_sec);
|
||||
}
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user