Skip to content

Commit 4a3e424

Browse files
committed
fix: gmtime_r and localtime_r is inline function on MinGW
1 parent b03c16a commit 4a3e424

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

src/spec.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,12 @@ static int zlog_spec_write_time_internal(zlog_spec_t * a_spec, zlog_thread_t * a
6262
time_t now_sec = a_thread->event->time_stamp.tv_sec;
6363
struct tm *time;
6464
time_t *time_sec;
65-
typedef struct tm *(*zlog_spec_time_fn) (const time_t*, struct tm *);
66-
zlog_spec_time_fn time_stamp_convert_function;
6765
if( use_utc ) {
6866
time = &(a_thread->event->time_utc);
6967
time_sec = &(a_thread->event->time_utc_sec);
70-
#ifdef _WIN32
71-
time_stamp_convert_function = gmtime_s;
72-
#else
73-
time_stamp_convert_function = gmtime_r;
74-
#endif
7568
} else {
7669
time = &(a_thread->event->time_local);
7770
time_sec = &(a_thread->event->time_local_sec);
78-
#ifdef _WIN32
79-
time_stamp_convert_function = localtime_s;
80-
#else
81-
time_stamp_convert_function = localtime_r;
82-
#endif
8371
}
8472

8573
/* the event meet the 1st time_spec in his life cycle */
@@ -90,7 +78,11 @@ static int zlog_spec_write_time_internal(zlog_spec_t * a_spec, zlog_thread_t * a
9078

9179
/* When this event's last cached time_local is not now */
9280
if (*time_sec != now_sec) {
93-
time_stamp_convert_function(&(now_sec), time);
81+
if (use_utc) {
82+
gmtime_r(&(now_sec), time);
83+
} else {
84+
localtime_r(&(now_sec), time);
85+
}
9486
*time_sec = now_sec;
9587
}
9688

src/zc_xplatform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
5353
#define zlog_fstat fstat64
5454
#define zlog_stat stat64
55-
#elif defined(_WIN32)
55+
#elif defined(_WIN32) && !defined(__MINGW32__)
5656
#define zlog_fstat _fstat
5757
#define zlog_stat _stat
5858
#else

0 commit comments

Comments
 (0)