Skip to content

Commit b03c16a

Browse files
committed
fix: build with windows mingw
1 parent 3715879 commit b03c16a

4 files changed

Lines changed: 24 additions & 1 deletion

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,19 @@ static int zlog_spec_write_time_internal(zlog_spec_t * a_spec, zlog_thread_t * a
6767
if( use_utc ) {
6868
time = &(a_thread->event->time_utc);
6969
time_sec = &(a_thread->event->time_utc_sec);
70+
#ifdef _WIN32
71+
time_stamp_convert_function = gmtime_s;
72+
#else
7073
time_stamp_convert_function = gmtime_r;
74+
#endif
7175
} else {
7276
time = &(a_thread->event->time_local);
7377
time_sec = &(a_thread->event->time_local_sec);
78+
#ifdef _WIN32
79+
time_stamp_convert_function = localtime_s;
80+
#else
7481
time_stamp_convert_function = localtime_r;
82+
#endif
7583
}
7684

7785
/* the event meet the 1st time_spec in his life cycle */
@@ -264,13 +272,15 @@ static int zlog_spec_write_tid_long(zlog_spec_t * a_spec, zlog_thread_t * a_thre
264272
return zlog_buf_append(a_buf, a_thread->event->tid_str, a_thread->event->tid_str_len);
265273
}
266274

275+
#if defined __linux__ || __APPLE__
267276
static int zlog_spec_write_ktid(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
268277
{
269278

270279
/* don't need to get ktid again, as tmap_new_thread fetched it already */
271280
/* and fork not change tid */
272281
return zlog_buf_append(a_buf, a_thread->event->ktid_str, a_thread->event->ktid_str_len);
273282
}
283+
#endif
274284

275285
static int zlog_spec_write_level_lowercase(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
276286
{
@@ -647,9 +657,11 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
647657
case 'H':
648658
a_spec->write_buf = zlog_spec_write_hostname;
649659
break;
660+
#if defined __linux__ || __APPLE__
650661
case 'k':
651662
a_spec->write_buf = zlog_spec_write_ktid;
652663
break;
664+
#endif
653665
case 'L':
654666
a_spec->write_buf = zlog_spec_write_srcline;
655667
break;

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)