Modify function from localtime to localtime_r

This commit is contained in:
zonda yang 2021-11-07 00:04:20 +08:00
parent f9ea34994b
commit 7dc98a0d1b
2 changed files with 5 additions and 5 deletions

View File

@ -52,7 +52,7 @@ static const char *level_colors[] = {
static void stdout_callback(log_Event *ev) {
char buf[16];
buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0';
buf[strftime(buf, sizeof(buf), "%H:%M:%S", &ev->time)] = '\0';
#ifdef LOG_USE_COLOR
fprintf(
ev->udata, "%s %s%-5s\x1b[0m \x1b[90m%s:%d:\x1b[0m ",
@ -71,7 +71,7 @@ static void stdout_callback(log_Event *ev) {
static void file_callback(log_Event *ev) {
char buf[64];
buf[strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ev->time)] = '\0';
buf[strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ev->time)] = '\0';
fprintf(
ev->udata, "%s %-5s %s:%d: ",
buf, level_strings[ev->level], ev->file, ev->line);
@ -129,9 +129,9 @@ int log_add_fp(FILE *fp, int level) {
static void init_event(log_Event *ev, void *udata) {
if (!ev->time) {
if (!(&ev->time)) {
time_t t = time(NULL);
ev->time = localtime(&t);
localtime_r(&t, &ev->time);
}
ev->udata = udata;
}

View File

@ -19,7 +19,7 @@ typedef struct {
va_list ap;
const char *fmt;
const char *file;
struct tm *time;
struct tm time;
void *udata;
int line;
int level;