diff --git a/ChangeLog b/ChangeLog index 803fbda54..be9f3e679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2001-10-04 Lutz Müller + + * libgphoto2/debug.c: Move debugging stuff to libgphoto2_port so + that those messages get saved, too. + 2001-10-04 Lutz Müller * camlibs/konica/library.c: const diff --git a/libgphoto2/debug.c b/libgphoto2/debug.c index e465e2e44..80b49fdcf 100644 --- a/libgphoto2/debug.c +++ b/libgphoto2/debug.c @@ -26,20 +26,27 @@ #include #include +#include static int glob_debug = GP_DEBUG_NONE; static GPDebugFunc debug_func = NULL; static void *debug_func_data = NULL; -static unsigned int debug_history_size = 0; -static char *debug_history = NULL; +static void +gp_port_func (const char *msg, void *data) +{ + if (debug_func) + debug_func ("port", msg, data); +} void gp_debug_set_func (GPDebugFunc func, void *data) { debug_func = func; debug_func_data = data; + + gp_port_debug_set_func (gp_port_func, data); } void @@ -47,35 +54,12 @@ gp_debug_printf (int level, const char *id, const char *format, ...) { char buffer[2048]; va_list arg; - int i; va_start (arg, format); vsprintf (buffer, format, arg); va_end (arg); - /* Create history if needed */ - if (!debug_history) { - debug_history_size = 1024; - debug_history = malloc (sizeof (char) * debug_history_size); - memset (debug_history, 0, debug_history_size); - } - - /* Do we have to forget parts of the debug history? */ - while (debug_history_size - strlen (debug_history) < - strlen (buffer) + 1) { - - /* Determine len of first entry */ - for (i = 0; debug_history[i] != '\0'; i++) - if (debug_history[i] == '\n') - break; - - /* Remove the first entry */ - memmove (debug_history, debug_history + i + 1, - strlen (debug_history) - i); - } - - strcat (debug_history, buffer); - strcat (debug_history, "\n"); + gp_port_debug_history_append (buffer); if (glob_debug == GP_DEBUG_NONE) return; @@ -84,9 +68,6 @@ gp_debug_printf (int level, const char *id, const char *format, ...) if (debug_func) { /* Custom debug function */ - va_start (arg, format); - vsprintf (buffer, format, arg); - va_end (arg); debug_func (id, buffer, debug_func_data); } else { @@ -119,23 +100,13 @@ gp_debug_get_level (void) const char * gp_debug_history_get (void) { - return (debug_history); + return (gp_port_debug_history_get ()); } int gp_debug_history_set_size (unsigned int size) { - char *new_debug_history; - - new_debug_history = realloc (debug_history, sizeof (char) * size); - - if (!new_debug_history) - return (GP_ERROR_NO_MEMORY); - - debug_history_size = size; - debug_history = new_debug_history; - - return (GP_OK); + return (gp_port_debug_history_set_size (size)); }