Use localtime_r

This commit is contained in:
blankie 2023-02-03 11:59:51 +07:00
parent 9e73720525
commit 04c46e220f
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 6 additions and 3 deletions

View File

@ -16,8 +16,9 @@ LogEntry::LogEntry(time_t time_, std::string message_) : time(time_), message(st
std::string format_log(const LogEntry& entry) {
struct tm tm;
char time_as_str[128] = {0};
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&entry.time));
strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&entry.time, &tm));
return std::string(1, '[') + time_as_str + "] " + entry.message;
}

View File

@ -22,8 +22,9 @@ static inline void render_table(ImFont* monospace_font, bool* autoscrolling) {
size_t i = static_cast<size_t>(i_u);
const LogEntry* log_entry = &log_entries[i];
struct tm tm;
char time_as_str[128] = {0};
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&log_entry->time));
strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&log_entry->time, &tm));
ImGui::TableNextRow();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);

View File

@ -27,8 +27,9 @@ static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>
while (clipper.Step()) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
const LogcatEntry* logcat_entry = &logcat_entries[filtered_logcat_entry_offsets[static_cast<size_t>(i)]];
struct tm tm;
char time_as_str[128] = {0};
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&logcat_entry->time));
strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&logcat_entry->time, &tm));
ImGui::TableNextRow();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);