Implement and use varargs interface to mingw_spawnvpe
[git-cheetah/kirill.git] / debug.c
blob37008a9a9ed19333834cd65af431d44fa68b11e0
1 #include <stdarg.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <windows.h> /* MB_OK */
5 #include "debug.h"
7 static char debug_git_file[MAX_PATH];
8 static FILE * debug_git_fd = NULL;
10 void debug_git_set_file(const char * filename)
12 if (debug_git_fd)
14 fclose(debug_git_fd);
15 debug_git_fd = NULL;
18 strncpy(debug_git_file, filename, MAX_PATH);
19 debug_git_file[MAX_PATH-1] = '\0';
21 debug_git_fd = fopen(debug_git_file, "a+");
24 void debug_git(char * format, ...)
26 if (!debug_git_fd)
28 debug_git_set_file(DEFAULT_DEBUG_GIT_FILE);
31 /* Check again in case the above debug_git_set_file failed. */
32 if (debug_git_fd)
34 va_list params;
35 char buffer[1024];
36 int length = 0;
38 va_start(params, format);
39 length = vsnprintf(buffer, sizeof(buffer), format, params);
40 va_end(params);
41 fwrite(buffer, sizeof(char), length, debug_git_fd);
42 fputc('\n', debug_git_fd);
43 fflush(debug_git_fd);
47 void debug_git_mbox(char *format, ...)
49 va_list params;
50 char buffer[1024];
52 va_start(params, format);
53 vsnprintf(buffer, sizeof(buffer), format, params);
54 va_end(params);
55 MessageBox(0, buffer, "Hello", MB_OK|MB_ICONEXCLAMATION);