Skip to content

Commit

Permalink
Merge branch 'ef/mingw-syslog'
Browse files Browse the repository at this point in the history
* ef/mingw-syslog:
  mingw: avoid using strbuf in syslog
  • Loading branch information
Junio C Hamano committed Oct 18, 2011
2 parents 33ce7c1 + 2a6b149 commit d2843da
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions compat/win32/syslog.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "../../git-compat-util.h"
#include "../../strbuf.h"

static HANDLE ms_eventlog;

Expand All @@ -16,13 +15,8 @@ void openlog(const char *ident, int logopt, int facility)

void syslog(int priority, const char *fmt, ...)
{
struct strbuf sb = STRBUF_INIT;
struct strbuf_expand_dict_entry dict[] = {
{"1", "% 1"},
{NULL, NULL}
};
WORD logtype;
char *str;
char *str, *pos;
int str_len;
va_list ap;

Expand All @@ -39,11 +33,24 @@ void syslog(int priority, const char *fmt, ...)
}

str = malloc(str_len + 1);
if (!str) {
warning("malloc failed: '%s'", strerror(errno));
return;
}

va_start(ap, fmt);
vsnprintf(str, str_len + 1, fmt, ap);
va_end(ap);
strbuf_expand(&sb, str, strbuf_expand_dict_cb, &dict);
free(str);

while ((pos = strstr(str, "%1")) != NULL) {
str = realloc(str, ++str_len + 1);
if (!str) {
warning("realloc failed: '%s'", strerror(errno));
return;
}
memmove(pos + 2, pos + 1, strlen(pos));
pos[1] = ' ';
}

switch (priority) {
case LOG_EMERG:
Expand All @@ -66,7 +73,6 @@ void syslog(int priority, const char *fmt, ...)
}

ReportEventA(ms_eventlog, logtype, 0, 0, NULL, 1, 0,
(const char **)&sb.buf, NULL);

strbuf_release(&sb);
(const char **)&str, NULL);
free(str);
}

0 comments on commit d2843da

Please sign in to comment.