summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2018-11-17 05:27:49 +0100
committerGuillem Jover <guillem@debian.org>2019-01-22 13:41:55 +0100
commit23cfdbf1054a3c9fdef741cdc5f6769b3fd57413 (patch)
tree5983da5d25eca273653d891387ad6720c4ff7e24 /lib
parent31eb544919a46c6170ac39f5eebd17ba6d48d508 (diff)
downloaddpkg-23cfdbf1054a3c9fdef741cdc5f6769b3fd57413.tar.gz
libdpkg: Add new warning printer setter function
This will make it possible for library users to specify alternative warning printers. Prompted-by: Julian Andres Klode <jak@debian.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/dpkg/libdpkg.map2
-rw-r--r--lib/dpkg/report.c22
-rw-r--r--lib/dpkg/report.h5
3 files changed, 26 insertions, 3 deletions
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index fe4e299ee..359418992 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -55,6 +55,8 @@ LIBDPKG_PRIVATE {
do_internerr;
dpkg_set_report_piped_mode;
dpkg_set_report_buffer;
+ dpkg_warning_printer;
+ dpkg_set_warning_printer;
warning_get_count;
warningv;
warning;
diff --git a/lib/dpkg/report.c b/lib/dpkg/report.c
index 58df60006..f7763b362 100644
--- a/lib/dpkg/report.c
+++ b/lib/dpkg/report.c
@@ -51,6 +51,24 @@ dpkg_set_report_buffer(FILE *fp)
setvbuf(fp, NULL, piped_mode, 0);
}
+void
+dpkg_warning_printer(const char *msg, void *data)
+{
+ fprintf(stderr, "%s%s:%s %s%s:%s %s\n",
+ color_get(COLOR_PROG), dpkg_get_progname(), color_reset(),
+ color_get(COLOR_WARN), _("warning"), color_reset(), msg);
+}
+
+static dpkg_warning_printer_func *warning_printer_func = dpkg_warning_printer;
+static void *warning_printer_data;
+
+void
+dpkg_set_warning_printer(dpkg_warning_printer_func *printer, void *data)
+{
+ warning_printer_func = printer;
+ warning_printer_data = data;
+}
+
static int warn_count = 0;
int
@@ -67,9 +85,7 @@ warningv(const char *fmt, va_list args)
warn_count++;
m_vasprintf(&buf, fmt, args);
- fprintf(stderr, "%s%s:%s %s%s:%s %s\n",
- color_get(COLOR_PROG), dpkg_get_progname(), color_reset(),
- color_get(COLOR_WARN), _("warning"), color_reset(), buf);
+ warning_printer_func(buf, warning_printer_data);
free(buf);
}
diff --git a/lib/dpkg/report.h b/lib/dpkg/report.h
index 4cadc7fe3..862a8429a 100644
--- a/lib/dpkg/report.h
+++ b/lib/dpkg/report.h
@@ -38,6 +38,11 @@ DPKG_BEGIN_DECLS
void dpkg_set_report_piped_mode(int mode);
void dpkg_set_report_buffer(FILE *fp);
+typedef void dpkg_warning_printer_func(const char *msg, void *data);
+
+void dpkg_warning_printer(const char *msg, void *data);
+void dpkg_set_warning_printer(dpkg_warning_printer_func *printer, void *data);
+
int warning_get_count(void);
void warningv(const char *fmt, va_list args) DPKG_ATTR_VPRINTF(1);
void warning(const char *fmt, ...) DPKG_ATTR_PRINTF(1);