From 259ead07dd49045a49916c042032527e7d0be52f Mon Sep 17 00:00:00 2001 From: graham.gower Date: Thu, 17 Dec 2009 01:42:43 -0500 Subject: Add a message callback function to the config struct for libopkg users. git-svn-id: http://opkg.googlecode.com/svn/trunk@496 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h index 67b660f..52498f5 100644 --- a/libopkg/opkg_conf.h +++ b/libopkg/opkg_conf.h @@ -57,6 +57,9 @@ struct opkg_conf uint pfm; /* package field mask */ + /* For libopkg users to capture messages. */ + void (*opkg_vmessage)(int, const char *fmt, va_list ap); + /* options */ int autoremove; int force_depends; diff --git a/libopkg/opkg_message.c b/libopkg/opkg_message.c index a21a1a2..81afc97 100644 --- a/libopkg/opkg_message.c +++ b/libopkg/opkg_message.c @@ -78,14 +78,26 @@ opkg_message (message_level_t level, const char *fmt, ...) { va_list ap; - if (conf && (conf->verbosity < level)) + if (conf->verbosity < level) return; + if (conf->opkg_vmessage) { + /* Pass the message to libopkg users. */ + va_start (ap, fmt); + conf->opkg_vmessage(level, fmt, ap); + va_end (ap); + return; + } + va_start (ap, fmt); if (level == ERROR) { - char msg[256]; - vsnprintf(msg, 256, fmt, ap); +#define MSG_LEN 256 + char msg[MSG_LEN]; + if (vsnprintf(msg, MSG_LEN, fmt, ap) >= MSG_LEN) { + fprintf(stderr, "%s: Message truncated!\n", + __FUNCTION__); + } push_error_list(msg); } else vprintf(fmt, ap); -- cgit v0.9.1