diff options
author | Arisotura <thetotalworm@gmail.com> | 2020-10-26 20:47:30 +0100 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2020-10-26 20:47:30 +0100 |
commit | fc922ffb14da3aa087a7eebeb55d09cf3b856e0d (patch) | |
tree | 68ad639693d7b97d286e71364ac796bfaaeefd7b /src/RTC.cpp | |
parent | 8d42b1c7d7466abf80a61ea51ee3006110c15b65 (diff) | |
parent | 49a96f41daa53ffa5dc4a46bdac4ee68f0b7eaee (diff) |
Merge branch 'master' into dsi_camera
# Conflicts:
# src/DSi_I2C.cpp
Diffstat (limited to 'src/RTC.cpp')
-rw-r--r-- | src/RTC.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/RTC.cpp b/src/RTC.cpp index ba51dff..aff3dd3 100644 --- a/src/RTC.cpp +++ b/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); - - 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); + 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); } break; case 0x60: { - time_t timestamp; - struct tm* timedata; - time(×tamp); - timedata = localtime(×tamp); - - Output[0] = BCD(timedata->tm_hour); - Output[1] = BCD(timedata->tm_min); - Output[2] = BCD(timedata->tm_sec); + 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); } break; |