summaryrefslogtreecommitdiff
path: root/drivers/unix/os_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix/os_unix.cpp')
-rw-r--r--drivers/unix/os_unix.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 3c212cadb8..96c338f86b 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -48,7 +48,7 @@
#include <mach/mach_time.h>
#endif
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/param.h>
#include <sys/sysctl.h>
#endif
@@ -171,52 +171,53 @@ double OS_Unix::get_unix_time() const {
OS::Date OS_Unix::get_date(bool utc) const {
time_t t = time(nullptr);
- struct tm *lt;
+ struct tm lt;
if (utc) {
- lt = gmtime(&t);
+ gmtime_r(&t, &lt);
} else {
- lt = localtime(&t);
+ localtime_r(&t, &lt);
}
Date ret;
- ret.year = 1900 + lt->tm_year;
+ ret.year = 1900 + lt.tm_year;
// Index starting at 1 to match OS_Unix::get_date
// and Windows SYSTEMTIME and tm_mon follows the typical structure
// of 0-11, noted here: http://www.cplusplus.com/reference/ctime/tm/
- ret.month = (Month)(lt->tm_mon + 1);
- ret.day = lt->tm_mday;
- ret.weekday = (Weekday)lt->tm_wday;
- ret.dst = lt->tm_isdst;
+ ret.month = (Month)(lt.tm_mon + 1);
+ ret.day = lt.tm_mday;
+ ret.weekday = (Weekday)lt.tm_wday;
+ ret.dst = lt.tm_isdst;
return ret;
}
OS::Time OS_Unix::get_time(bool utc) const {
time_t t = time(nullptr);
- struct tm *lt;
+ struct tm lt;
if (utc) {
- lt = gmtime(&t);
+ gmtime_r(&t, &lt);
} else {
- lt = localtime(&t);
+ localtime_r(&t, &lt);
}
Time ret;
- ret.hour = lt->tm_hour;
- ret.min = lt->tm_min;
- ret.sec = lt->tm_sec;
+ ret.hour = lt.tm_hour;
+ ret.min = lt.tm_min;
+ ret.sec = lt.tm_sec;
get_time_zone_info();
return ret;
}
OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
time_t t = time(nullptr);
- struct tm *lt = localtime(&t);
+ struct tm lt;
+ localtime_r(&t, &lt);
char name[16];
- strftime(name, 16, "%Z", lt);
+ strftime(name, 16, "%Z", &lt);
name[15] = 0;
TimeZoneInfo ret;
ret.name = name;
char bias_buf[16];
- strftime(bias_buf, 16, "%z", lt);
+ strftime(bias_buf, 16, "%z", &lt);
int bias;
bias_buf[15] = 0;
sscanf(bias_buf, "%d", &bias);
@@ -476,7 +477,7 @@ String OS_Unix::get_executable_path() const {
return OS::get_executable_path();
}
return b;
-#elif defined(__OpenBSD__)
+#elif defined(__OpenBSD__) || defined(__NetBSD__)
char resolved_path[MAXPATHLEN];
realpath(OS::get_executable_path().utf8().get_data(), resolved_path);