Replace localtime() with thread-safe fmt::localtime()

This commit is contained in:
Richard Berger
2021-05-07 19:53:18 -04:00
parent b6b70b2033
commit 86d4ec7a45
3 changed files with 18 additions and 16 deletions

View File

@ -22,6 +22,7 @@
#include "neighbor.h"
#include "suffix.h"
#include "update.h"
#include "fmt/chrono.h"
#include <ctime>
@ -283,14 +284,13 @@ void Bond::write_file(int narg, char **arg)
"DATE: {}\n", table_file, date);
fp = fopen(table_file.c_str(),"a");
} else {
char datebuf[16];
time_t tv = time(nullptr);
strftime(datebuf,15,"%Y-%m-%d",localtime(&tv));
std::tm current_date = fmt::localtime(tv);
utils::logmesg(lmp,"Creating table file {} with "
"DATE: {}\n", table_file, datebuf);
"DATE: {:%Y-%m-%d}\n", table_file, current_date);
fp = fopen(table_file.c_str(),"w");
if (fp) fmt::print(fp,"# DATE: {} UNITS: {} Created by bond_write\n",
datebuf, update->unit_style);
if (fp) fmt::print(fp,"# DATE: {:%Y-%m-%d} UNITS: {} Created by bond_write\n",
current_date, update->unit_style);
}
if (fp == nullptr)
error->one(FLERR,"Cannot open bond_write file {}: {}",