dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / report.c
CommitLineData
1479465f
GJ
1/*
2 * libdpkg - Debian packaging suite library routines
3 * report.c - message reporting
4 *
5 * Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>
6 * Copyright © 2008-2013 Guillem Jover <guillem@debian.org>
7 *
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.
12 *
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.
17 *
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/>.
20 */
21
22#include <config.h>
23#include <compat.h>
24
25#include <stdarg.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <unistd.h>
29
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>
36
37static int piped_mode = _IOLBF;
38
39void
40dpkg_set_report_piped_mode(int mode)
41{
42 piped_mode = mode;
43}
44
45void
46dpkg_set_report_buffer(FILE *fp)
47{
48 if (isatty(fileno(fp)))
49 setvbuf(fp, NULL, _IONBF, 0);
50 else
51 setvbuf(fp, NULL, piped_mode, 0);
52}
53
54static int warn_count = 0;
55
56int
57warning_get_count(void)
58{
59 return warn_count;
60}
61
62void
63warningv(const char *fmt, va_list args)
64{
65 char *buf = NULL;
66
67 warn_count++;
68
69 m_vasprintf(&buf, fmt, args);
70 fprintf(stderr, "%s%s:%s %s%s:%s %s\n",
71 color_get(COLOR_PROG), dpkg_get_progname(), color_reset(),
72 color_get(COLOR_WARN), _("warning"), color_reset(), buf);
73 free(buf);
74}
75
76void
77warning(const char *fmt, ...)
78{
79 va_list args;
80
81 va_start(args, fmt);
82 warningv(fmt, args);
83 va_end(args);
84}
85
86void
87notice(const char *fmt, ...)
88{
89 char *buf = NULL;
90 va_list args;
91
92 va_start(args, fmt);
93 m_vasprintf(&buf, fmt, args);
94 va_end(args);
95
96 fprintf(stderr, "%s%s:%s %s\n",
97 color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
98
99 free(buf);
100}
101
102void
103info(const char *fmt, ...)
104{
105 char *buf;
106 va_list args;
107
108 va_start(args, fmt);
109 m_vasprintf(&buf, fmt, args);
110 va_end(args);
111
112 printf("%s%s:%s %s\n",
113 color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
114
115 free(buf);
116}