1 /*
2  * libdpkg - Debian packaging suite library routines
3  * error.h - error message reporting
4  *
5  * Copyright © 2011-2015 Guillem Jover <guillem@debian.org>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef LIBDPKG_ERROR_H
22 #define LIBDPKG_ERROR_H
23 
24 #include <stdbool.h>
25 
26 #include <dpkg/macros.h>
27 
28 DPKG_BEGIN_DECLS
29 
30 /**
31  * @defgroup dpkg_error Error message reporting
32  * @ingroup dpkg-public
33  * @{
34  */
35 
36 enum dpkg_msg_type {
37 	DPKG_MSG_NONE,
38 	DPKG_MSG_WARN,
39 	DPKG_MSG_ERROR,
40 };
41 
42 struct dpkg_error {
43 	enum dpkg_msg_type type;
44 
45 	int syserrno;
46 	char *str;
47 };
48 
49 #define DPKG_ERROR_INIT { DPKG_MSG_NONE, 0, NULL }
50 
51 #define DPKG_ERROR_OBJECT (struct dpkg_error)DPKG_ERROR_INIT
52 
53 bool dpkg_has_error(struct dpkg_error *err);
54 
55 int dpkg_put_warn(struct dpkg_error *err, const char *fmt, ...)
56 	DPKG_ATTR_PRINTF(2);
57 int dpkg_put_error(struct dpkg_error *err, const char *fmt, ...)
58 	DPKG_ATTR_PRINTF(2);
59 int dpkg_put_errno(struct dpkg_error *err, const char *fmt, ...)
60 	DPKG_ATTR_PRINTF(2);
61 
62 void dpkg_error_print(struct dpkg_error *err, const char *fmt, ...)
63 	DPKG_ATTR_PRINTF(2);
64 
65 void dpkg_error_move(struct dpkg_error *dst, struct dpkg_error *src);
66 void dpkg_error_destroy(struct dpkg_error *err);
67 
68 /** @} */
69 
70 DPKG_END_DECLS
71 
72 #endif /* LIBDPKG_ERROR_H */
73