Revert "sq h2"
[metze/wireshark/wip.git] / wsutil / report_message.c
1 /* report_message.c
2  * Routines for code that can run in GUI and command-line environments to
3  * use to report errors and warnings to the user (e.g., I/O errors, or
4  * problems with preference settings) if the message should be shown as
5  * a GUI error in a GUI environment.
6  *
7  * The application using libwsutil will register error-reporting
8  * routines, and the routines defined here will call the registered
9  * routines.  That way, these routines can be called by code that
10  * doesn't itself know whether to pop up a dialog or print something
11  * to the standard error.
12  *
13  * Wireshark - Network traffic analyzer
14  * By Gerald Combs <gerald@wireshark.org>
15  * Copyright 1998 Gerald Combs
16  *
17  * SPDX-License-Identifier: GPL-2.0-or-later
18  */
19 #include "config.h"
20
21 #include <glib.h>
22 #include "report_message.h"
23
24 static void (*vreport_failure_func)(const char *, va_list);
25 static void (*vreport_warning_func)(const char *, va_list);
26 static void (*report_open_failure_func)(const char *, int, gboolean);
27 static void (*report_read_failure_func)(const char *, int);
28 static void (*report_write_failure_func)(const char *, int);
29
30 void init_report_message(void (*vreport_failure_fcn_p)(const char *, va_list),
31                          void (*vreport_warning_fcn_p)(const char *, va_list),
32                          void (*report_open_failure_fcn_p)(const char *, int, gboolean),
33                          void (*report_read_failure_fcn_p)(const char *, int),
34                          void (*report_write_failure_fcn_p)(const char *, int))
35 {
36         vreport_failure_func = vreport_failure_fcn_p;
37         vreport_warning_func = vreport_warning_fcn_p;
38         report_open_failure_func = report_open_failure_fcn_p;
39         report_read_failure_func = report_read_failure_fcn_p;
40         report_write_failure_func = report_write_failure_fcn_p;
41 }
42
43 /*
44  * Report a general error.
45  */
46 void
47 report_failure(const char *msg_format, ...)
48 {
49         va_list ap;
50
51         va_start(ap, msg_format);
52         (*vreport_failure_func)(msg_format, ap);
53         va_end(ap);
54 }
55
56 /*
57  * Report a general warning.
58  */
59 void
60 report_warning(const char *msg_format, ...)
61 {
62         va_list ap;
63
64         va_start(ap, msg_format);
65         (*vreport_warning_func)(msg_format, ap);
66         va_end(ap);
67 }
68
69 /*
70  * Report an error when trying to open or create a file.
71  * "err" is assumed to be an error code from Wiretap; positive values are
72  * UNIX-style errnos, so this can be used for open failures not from
73  * Wiretap as long as the failure code is just an errno.
74  */
75 void
76 report_open_failure(const char *filename, int err,
77                                         gboolean for_writing)
78 {
79         (*report_open_failure_func)(filename, err, for_writing);
80 }
81
82 /*
83  * Report an error when trying to read a file.
84  * "err" is assumed to be a UNIX-style errno.
85  */
86 void
87 report_read_failure(const char *filename, int err)
88 {
89         (*report_read_failure_func)(filename, err);
90 }
91
92 /*
93  * Report an error when trying to write a file.
94  * "err" is assumed to be a UNIX-style errno.
95  */
96 void
97 report_write_failure(const char *filename, int err)
98 {
99         (*report_write_failure_func)(filename, err);
100 }
101
102 /*
103  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
104  *
105  * Local variables:
106  * c-basic-offset: 8
107  * tab-width: 8
108  * indent-tabs-mode: t
109  * End:
110  *
111  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
112  * :indentSize=8:tabSize=8:noTabs=false:
113  */