aboutsummaryrefslogtreecommitdiff
path: root/src/RTC.cpp
diff options
context:
space:
mode:
authorWaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com>2020-10-23 00:39:29 +0100
committerGitHub <noreply@github.com>2020-10-23 00:39:29 +0100
commit8d70d0926c6307368398a894cbebfbdc0f538194 (patch)
tree72774a626ff8a30850c36eba33fdac38962739cb /src/RTC.cpp
parenta8851a51f19577f153a3fa5d1021be5794f0921a (diff)
parent65be1840f02a7499fa08178abcefddfefec6d9b0 (diff)
Merge branch 'master' into feature/zip-support
Diffstat (limited to 'src/RTC.cpp')
-rw-r--r--src/RTC.cpp41
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(&timestamp);
- timedata = localtime(&timestamp);
-
- 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(&timestamp, &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(&timestamp);
- timedata = localtime(&timestamp);
-
- 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(&timestamp, &timedata);
+
+ Output[0] = BCD(timedata.tm_hour);
+ Output[1] = BCD(timedata.tm_min);
+ Output[2] = BCD(timedata.tm_sec);
}
break;