regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / wsutil / report_message.c
blobdf2c55ce952790cd91a4d10796b1c109ff1d1f93
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.
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.
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include "config.h"
21 #include "report_message.h"
23 static const char *friendly_program_name;
24 static const struct report_message_routines *routines;
26 void
27 init_report_message(const char *friendly_program_name_arg,
28 const struct report_message_routines *routines_arg)
30 friendly_program_name = friendly_program_name_arg;
31 routines = routines_arg;
35 * Report a general error.
37 void
38 report_failure(const char *msg_format, ...)
40 va_list ap;
42 va_start(ap, msg_format);
43 (*routines->vreport_failure)(msg_format, ap);
44 va_end(ap);
48 * Report a general warning.
50 void
51 report_warning(const char *msg_format, ...)
53 va_list ap;
55 va_start(ap, msg_format);
56 (*routines->vreport_warning)(msg_format, ap);
57 va_end(ap);
61 * Report an error when trying to open or create a file.
62 * "err" is assumed to be an error code from Wiretap; positive values are
63 * UNIX-style errnos, so this can be used for open failures not from
64 * Wiretap as long as the failure code is just an errno.
66 void
67 report_open_failure(const char *filename, int err,
68 bool for_writing)
70 (*routines->report_open_failure)(filename, err, for_writing);
74 * Report an error when trying to read a file.
75 * "err" is assumed to be a UNIX-style errno.
77 void
78 report_read_failure(const char *filename, int err)
80 (*routines->report_read_failure)(filename, err);
84 * Report an error when trying to write a file.
85 * "err" is assumed to be a UNIX-style errno.
87 void
88 report_write_failure(const char *filename, int err)
90 (*routines->report_write_failure)(filename, err);
94 * Report an error when trying to rename a file.
95 * "err" is assumed to be a UNIX-style errno.
97 void
98 report_rename_failure(const char *old_filename, const char *new_filename,
99 int err)
101 (*routines->report_rename_failure)(old_filename, new_filename, err);
105 * Report an error from opening a capture file for reading.
107 void
108 report_cfile_open_failure(const char *filename, int err, char *err_info)
110 (*routines->report_cfile_open_failure)(filename, err, err_info);
114 * Report an error from opening a capture file for writing.
116 void
117 report_cfile_dump_open_failure(const char *filename,
118 int err, char *err_info, int file_type_subtype)
120 (*routines->report_cfile_dump_open_failure)(filename,
121 err, err_info, file_type_subtype);
125 * Report an error from attempting to read from a capture file.
127 void
128 report_cfile_read_failure(const char *filename, int err, char *err_info)
130 (*routines->report_cfile_read_failure)(filename, err, err_info);
134 * Report an error from attempting to write to a capture file.
136 void
137 report_cfile_write_failure(const char *in_filename, const char *out_filename,
138 int err, char *err_info, uint64_t framenum, int file_type_subtype)
140 (*routines->report_cfile_write_failure)(in_filename, out_filename,
141 err, err_info, framenum, file_type_subtype);
145 * Report an error from closing a capture file open for writing.
147 void
148 report_cfile_close_failure(const char *filename, int err, char *err_info)
150 (*routines->report_cfile_close_failure)(filename, err, err_info);
154 * Return the "friendly" program name.
156 const char *
157 get_friendly_program_name(void)
159 return friendly_program_name;
163 * Editor modelines - https://www.wireshark.org/tools/modelines.html
165 * Local variables:
166 * c-basic-offset: 8
167 * tab-width: 8
168 * indent-tabs-mode: t
169 * End:
171 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
172 * :indentSize=8:tabSize=8:noTabs=false: