2 * libdpkg - Debian packaging suite library routines
3 * report.c - message reporting
5 * Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>
6 * Copyright © 2008-2013 Guillem Jover <guillem@debian.org>
8 * This is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 #include <dpkg/dpkg.h>
31 #include <dpkg/macros.h>
32 #include <dpkg/i18n.h>
33 #include <dpkg/progname.h>
34 #include <dpkg/color.h>
35 #include <dpkg/report.h>
37 static int piped_mode
= _IOLBF
;
40 dpkg_set_report_piped_mode(int mode
)
46 dpkg_set_report_buffer(FILE *fp
)
48 if (isatty(fileno(fp
)))
49 setvbuf(fp
, NULL
, _IONBF
, 0);
51 setvbuf(fp
, NULL
, piped_mode
, 0);
55 dpkg_warning_printer(const char *msg
, void *data
)
57 fprintf(stderr
, "%s%s:%s %s%s:%s %s\n",
58 color_get(COLOR_PROG
), dpkg_get_progname(), color_reset(),
59 color_get(COLOR_WARN
), _("warning"), color_reset(), msg
);
62 static dpkg_warning_printer_func
*warning_printer_func
= dpkg_warning_printer
;
63 static void *warning_printer_data
;
66 dpkg_set_warning_printer(dpkg_warning_printer_func
*printer
, void *data
)
68 warning_printer_func
= printer
;
69 warning_printer_data
= data
;
72 static int warn_count
= 0;
75 warning_get_count(void)
81 warningv(const char *fmt
, va_list args
)
87 m_vasprintf(&buf
, fmt
, args
);
88 warning_printer_func(buf
, warning_printer_data
);
93 warning(const char *fmt
, ...)
103 notice(const char *fmt
, ...)
109 m_vasprintf(&buf
, fmt
, args
);
112 fprintf(stderr
, "%s%s:%s %s\n",
113 color_get(COLOR_PROG
), dpkg_get_progname(), color_reset(), buf
);
119 info(const char *fmt
, ...)
125 m_vasprintf(&buf
, fmt
, args
);
128 printf("%s%s:%s %s\n",
129 color_get(COLOR_PROG
), dpkg_get_progname(), color_reset(), buf
);