Reset inheritable flag of debug log file git_shell_ext_debug.txt
[git-cheetah/kirill.git] / common / debug.c
blob2d567fc2117ec82ff50f21c47c06180e3b087062
1 #include "git-compat-util.h"
2 #include "systeminfo.h"
3 #include "debug.h"
5 static FILE *debug_git_fp = NULL;
7 #ifdef _WIN32
8 static void reset_inherit_flag(FILE *file)
10 HANDLE handle;
12 if(!file)
13 return;
15 handle = (HANDLE)_get_osfhandle(_fileno(file));
16 SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0);
18 #endif
20 void debug_git(char * format, ...)
22 if (!debug_git_fp) {
23 #ifdef _WIN32
24 WCHAR path[MAX_PATH];
25 GetTempPathW(MAX_PATH, path);
26 wcsncat(path, L"git_shell_ext_debug.txt", MAX_PATH);
27 debug_git_fp = _wfopen(path, L"a+");
28 reset_inherit_flag(debug_git_fp);
29 #else
30 debug_git_fp = fopen("/tmp/git-cheetah-plugin.log", "a+");
31 #endif
34 /* Check again in case the above debug_git_set_file failed. */
35 if (debug_git_fp)
37 va_list params;
38 char buffer[1024];
39 int length = 0;
41 va_start(params, format);
42 length = vsnprintf(buffer, sizeof(buffer), format, params);
43 va_end(params);
44 fwrite(buffer, sizeof(char), length, debug_git_fp);
45 fputc('\n', debug_git_fp);
46 fflush(debug_git_fp);
50 void debug_git_mbox(char *format, ...)
52 va_list params;
53 char buffer[1024];
55 va_start(params, format);
56 vsnprintf(buffer, sizeof(buffer), format, params);
57 va_end(params);
58 message_box(buffer);