Skip to content

Commit 0922dd1

Browse files
committed
fix: build and run on windows with MinGW
1 parent 3715879 commit 0922dd1

5 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/event.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
#include <sys/time.h>
2929

3030
#include <sys/types.h>
31+
#if defined __linux__ || __APPLE__
3132
#include <sys/syscall.h>
32-
33+
#endif
3334
#include "zc_defs.h"
3435
#include "event.h"
3536
#ifdef _WIN32

src/fmacros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
#endif
2929
#endif
3030

31+
#ifdef _WIN32
32+
#ifndef _POSIX_C_SOURCE
33+
#define _POSIX_C_SOURCE 200809L
34+
#endif
35+
#endif
36+
3137
#ifndef _LARGEFILE_SOURCE
3238
#define _LARGEFILE_SOURCE
3339
#endif

src/spec.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +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-
time_stamp_convert_function = gmtime_r;
7168
} else {
7269
time = &(a_thread->event->time_local);
7370
time_sec = &(a_thread->event->time_local_sec);
74-
time_stamp_convert_function = localtime_r;
7571
}
7672

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

8379
/* When this event's last cached time_local is not now */
8480
if (*time_sec != now_sec) {
85-
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+
}
8686
*time_sec = now_sec;
8787
}
8888

@@ -241,7 +241,7 @@ static int zlog_spec_write_pid(zlog_spec_t * a_spec, zlog_thread_t * a_thread, z
241241
if (a_thread->event->pid != a_thread->event->last_pid) {
242242
a_thread->event->last_pid = a_thread->event->pid;
243243
a_thread->event->pid_str_len
244-
= sprintf(a_thread->event->pid_str, "%u", a_thread->event->pid);
244+
= sprintf(a_thread->event->pid_str, "%ld", (long)a_thread->event->pid);
245245
}
246246
}
247247

@@ -264,13 +264,15 @@ static int zlog_spec_write_tid_long(zlog_spec_t * a_spec, zlog_thread_t * a_thre
264264
return zlog_buf_append(a_buf, a_thread->event->tid_str, a_thread->event->tid_str_len);
265265
}
266266

267+
#if defined __linux__ || __APPLE__
267268
static int zlog_spec_write_ktid(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
268269
{
269270

270271
/* don't need to get ktid again, as tmap_new_thread fetched it already */
271272
/* and fork not change tid */
272273
return zlog_buf_append(a_buf, a_thread->event->ktid_str, a_thread->event->ktid_str_len);
273274
}
275+
#endif
274276

275277
static int zlog_spec_write_level_lowercase(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
276278
{
@@ -647,9 +649,11 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
647649
case 'H':
648650
a_spec->write_buf = zlog_spec_write_hostname;
649651
break;
652+
#if defined __linux__ || __APPLE__
650653
case 'k':
651654
a_spec->write_buf = zlog_spec_write_ktid;
652655
break;
656+
#endif
653657
case 'L':
654658
a_spec->write_buf = zlog_spec_write_srcline;
655659
break;

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

src/zlog-chk-conf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#include <stdarg.h>
2121
#include <string.h>
2222

23+
#ifndef _WIN32
2324
#include <unistd.h>
25+
#else
26+
#include "zlog_win.h"
27+
#endif
2428

2529
#include "zlog.h"
2630
#include "version.h"

0 commit comments

Comments
 (0)