Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#include <sys/time.h>

#include <sys/types.h>
#if defined __linux__ || __APPLE__
#include <sys/syscall.h>

#endif
#include "zc_defs.h"
#include "event.h"
#ifdef _WIN32
Expand Down
6 changes: 6 additions & 0 deletions src/fmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#endif
#endif

#ifdef _WIN32
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#endif

#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#endif
Expand Down
16 changes: 10 additions & 6 deletions src/spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,12 @@ static int zlog_spec_write_time_internal(zlog_spec_t * a_spec, zlog_thread_t * a
time_t now_sec = a_thread->event->time_stamp.tv_sec;
struct tm *time;
time_t *time_sec;
typedef struct tm *(*zlog_spec_time_fn) (const time_t*, struct tm *);
zlog_spec_time_fn time_stamp_convert_function;
if( use_utc ) {
time = &(a_thread->event->time_utc);
time_sec = &(a_thread->event->time_utc_sec);
time_stamp_convert_function = gmtime_r;
} else {
time = &(a_thread->event->time_local);
time_sec = &(a_thread->event->time_local_sec);
time_stamp_convert_function = localtime_r;
}

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

/* When this event's last cached time_local is not now */
if (*time_sec != now_sec) {
time_stamp_convert_function(&(now_sec), time);
if (use_utc) {
gmtime_r(&(now_sec), time);
} else {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On MinGW gmtime_r and localtime_r are inline functions, can't get function pointers

localtime_r(&(now_sec), time);
}
*time_sec = now_sec;
}

Expand Down Expand Up @@ -241,7 +241,7 @@ static int zlog_spec_write_pid(zlog_spec_t * a_spec, zlog_thread_t * a_thread, z
if (a_thread->event->pid != a_thread->event->last_pid) {
a_thread->event->last_pid = a_thread->event->pid;
a_thread->event->pid_str_len
= sprintf(a_thread->event->pid_str, "%u", a_thread->event->pid);
= sprintf(a_thread->event->pid_str, "%ld", (long)a_thread->event->pid);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Causes segmentation fault

}
}

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

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

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

static int zlog_spec_write_level_lowercase(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
{
Expand Down Expand Up @@ -647,9 +649,11 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
case 'H':
a_spec->write_buf = zlog_spec_write_hostname;
break;
#if defined __linux__ || __APPLE__
case 'k':
a_spec->write_buf = zlog_spec_write_ktid;
break;
#endif
case 'L':
a_spec->write_buf = zlog_spec_write_srcline;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/zc_xplatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
#define zlog_fstat fstat64
#define zlog_stat stat64
#elif defined(_WIN32)
#elif defined(_WIN32) && !defined(__MINGW32__)
#define zlog_fstat _fstat

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflict with MinGW defined macros

#define zlog_stat _stat
#else
Expand Down
4 changes: 4 additions & 0 deletions src/zlog-chk-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include <stdarg.h>
#include <string.h>

#ifndef _WIN32
#include <unistd.h>
#else
#include "zlog_win.h"
#endif

#include "zlog.h"
#include "version.h"
Expand Down