X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=src%2Fgrr_board_view.c;h=4a3b733713627e586b731617d873204bbe0615da;hb=85953690f1a640d11af15017628df86ab6f03e56;hp=c4cf316e49103c9c158bd5373c9fc237206f9f3b;hpb=a9073cef8cae5bddd59d7c6aff5decca20801e42;p=grrobot diff --git a/src/grr_board_view.c b/src/grr_board_view.c index c4cf316..4a3b733 100644 --- a/src/grr_board_view.c +++ b/src/grr_board_view.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -38,6 +37,7 @@ #include #include "grr_board_view.h" +#include "grr_util.h" #define SCROLL_DELAY_LENGTH 300 #define GRR_BOARD_VIEW_DEFAULT_SIZE 100 @@ -78,13 +78,6 @@ /* Forward declarations */ -static int -grr_sprintf_alloc (char **str, const char *fmt, ...); - -static int -grr_sprintf_alloc_va (char **str, const char *fmt, va_list ap); - - static void grr_board_view_class_init (grr_board_view_class_t *klass); static void grr_board_view_init (grr_board_view_t *view); static void grr_board_view_destroy (GtkObject *object); @@ -761,46 +754,3 @@ grr_board_view_update (grr_board_view_t *view) gtk_widget_queue_draw (GTK_WIDGET (view)); } -static int -grr_sprintf_alloc (char **str, const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = grr_sprintf_alloc_va (str, fmt, ap); - va_end(ap); - - return ret; -} - -/* ripped more or less straight out of PRINTF(3) */ -static int -grr_sprintf_alloc_va (char **str, const char *fmt, va_list ap) -{ - char *new_str; - /* Guess we need no more than 100 bytes. */ - int n, size = 100; - - if ((*str = malloc (size)) == NULL) - return -1; - while (1) { - /* Try to print in the allocated space. */ - n = vsnprintf (*str, size, fmt, ap); - /* If that worked, return the size. */ - if (n > -1 && n < size) - return n; - /* Else try again with more space. */ - if (n > -1) /* glibc 2.1 */ - size = n+1; /* precisely what is needed */ - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ - new_str = realloc(*str, size); - if (new_str == NULL) { - free(*str); - *str = NULL; - return -1; - } - *str = new_str; - } -}