1
1
#include "../../git-compat-util.h"
2
- #include "../../strbuf.h"
3
2
4
3
static HANDLE ms_eventlog ;
5
4
@@ -16,13 +15,8 @@ void openlog(const char *ident, int logopt, int facility)
16
15
17
16
void syslog (int priority , const char * fmt , ...)
18
17
{
19
- struct strbuf sb = STRBUF_INIT ;
20
- struct strbuf_expand_dict_entry dict [] = {
21
- {"1" , "% 1" },
22
- {NULL , NULL }
23
- };
24
18
WORD logtype ;
25
- char * str ;
19
+ char * str , * pos ;
26
20
int str_len ;
27
21
va_list ap ;
28
22
@@ -39,11 +33,24 @@ void syslog(int priority, const char *fmt, ...)
39
33
}
40
34
41
35
str = malloc (str_len + 1 );
36
+ if (!str ) {
37
+ warning ("malloc failed: '%s'" , strerror (errno ));
38
+ return ;
39
+ }
40
+
42
41
va_start (ap , fmt );
43
42
vsnprintf (str , str_len + 1 , fmt , ap );
44
43
va_end (ap );
45
- strbuf_expand (& sb , str , strbuf_expand_dict_cb , & dict );
46
- free (str );
44
+
45
+ while ((pos = strstr (str , "%1" )) != NULL ) {
46
+ str = realloc (str , ++ str_len + 1 );
47
+ if (!str ) {
48
+ warning ("realloc failed: '%s'" , strerror (errno ));
49
+ return ;
50
+ }
51
+ memmove (pos + 2 , pos + 1 , strlen (pos ));
52
+ pos [1 ] = ' ' ;
53
+ }
47
54
48
55
switch (priority ) {
49
56
case LOG_EMERG :
@@ -66,7 +73,6 @@ void syslog(int priority, const char *fmt, ...)
66
73
}
67
74
68
75
ReportEventA (ms_eventlog , logtype , 0 , 0 , NULL , 1 , 0 ,
69
- (const char * * )& sb .buf , NULL );
70
-
71
- strbuf_release (& sb );
76
+ (const char * * )& str , NULL );
77
+ free (str );
72
78
}
0 commit comments