summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libopkg/opkg_conf.h3
-rw-r--r--libopkg/opkg_message.c18
2 files changed, 18 insertions, 3 deletions
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);