From afb9ddb4705010ee2e8afd815889cb143c438902 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 8 Jun 2011 13:51:57 +0200 Subject: [PATCH] Simplify debug-log code While we're at it, rename debug_git_fd to debug_git_fp; it's a pointer to a FILE, not a file descriptor. Signed-off-by: Erik Faye-Lund --- common/debug.c | 34 +++++++++++----------------------- common/debug.h | 27 ++++++++------------------- 2 files changed, 19 insertions(+), 42 deletions(-) rewrite common/debug.h (61%) diff --git a/common/debug.c b/common/debug.c index d6ec75f..04efa7c 100644 --- a/common/debug.c +++ b/common/debug.c @@ -2,32 +2,20 @@ #include "systeminfo.h" #include "debug.h" -static char debug_git_file[MAX_PATH]; -static FILE * debug_git_fd = NULL; - -void debug_git_set_file(const char * filename) -{ - if (debug_git_fd) - { - fclose(debug_git_fd); - debug_git_fd = NULL; - } - - strncpy(debug_git_file, filename, MAX_PATH); - debug_git_file[MAX_PATH-1] = '\0'; - - debug_git_fd = fopen(debug_git_file, "a+"); -} +static FILE *debug_git_fp = NULL; void debug_git(char * format, ...) { - if (!debug_git_fd) - { - debug_git_set_file(DEFAULT_DEBUG_GIT_FILE); + if (!debug_git_fp) { +#ifdef _WIN32 + debug_git_fp = fopen("C:/git_shell_ext_debug.txt", "a+"); +#else + debug_git_fp = fopen("/tmp/git-cheetah-plugin.log", "a+"); +#endif } /* Check again in case the above debug_git_set_file failed. */ - if (debug_git_fd) + if (debug_git_fp) { va_list params; char buffer[1024]; @@ -36,9 +24,9 @@ void debug_git(char * format, ...) va_start(params, format); length = vsnprintf(buffer, sizeof(buffer), format, params); va_end(params); - fwrite(buffer, sizeof(char), length, debug_git_fd); - fputc('\n', debug_git_fd); - fflush(debug_git_fd); + fwrite(buffer, sizeof(char), length, debug_git_fp); + fputc('\n', debug_git_fp); + fflush(debug_git_fp); } } diff --git a/common/debug.h b/common/debug.h dissimilarity index 61% index 76f8825..45df708 100644 --- a/common/debug.h +++ b/common/debug.h @@ -1,19 +1,8 @@ -#ifndef DEBUG_H -#define DEBUG_H - -#ifdef _WIN32 -#define DEFAULT_DEBUG_GIT_FILE "C:/git_shell_ext_debug.txt" -#endif - -/* default in case no special path is needed */ -#ifndef DEFAULT_DEBUG_GIT_FILE -#define DEFAULT_DEBUG_GIT_FILE "/tmp/git-cheetah-plugin.log" -#endif - -void debug_git_set_file(const char * filename); - -typedef void reporter(char *format, ...); -void debug_git(char * format, ...); -void debug_git_mbox(char *format, ...); - -#endif /* DEBUG_H */ +#ifndef DEBUG_H +#define DEBUG_H + +typedef void reporter(char *format, ...); +void debug_git(char * format, ...); +void debug_git_mbox(char *format, ...); + +#endif /* DEBUG_H */ -- 2.11.4.GIT