2 * libdpkg - Debian packaging suite library routines
3 * error.c - error message reporting
5 * Copyright © 2011-2015 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
28 #include <dpkg/dpkg.h>
29 #include <dpkg/varbuf.h>
30 #include <dpkg/error.h>
32 static void DPKG_ATTR_VPRINTF(4)
33 dpkg_error_set(struct dpkg_error
*err
, enum dpkg_msg_type type
, int syserrno
,
34 const char *fmt
, va_list args
)
36 struct varbuf str
= VARBUF_INIT
;
42 err
->syserrno
= syserrno
;
44 varbuf_vprintf(&str
, fmt
, args
);
46 varbuf_printf(&str
, " (%s)", strerror(syserrno
));
52 dpkg_has_error(struct dpkg_error
*err
)
54 return err
!= NULL
&& err
->type
!= DPKG_MSG_NONE
;
58 dpkg_put_warn(struct dpkg_error
*err
, const char *fmt
, ...)
63 dpkg_error_set(err
, DPKG_MSG_WARN
, 0, fmt
, args
);
70 dpkg_put_error(struct dpkg_error
*err
, const char *fmt
, ...)
75 dpkg_error_set(err
, DPKG_MSG_ERROR
, 0, fmt
, args
);
82 dpkg_put_errno(struct dpkg_error
*err
, const char *fmt
, ...)
87 dpkg_error_set(err
, DPKG_MSG_ERROR
, errno
, fmt
, args
);
94 dpkg_error_print(struct dpkg_error
*err
, const char *fmt
, ...)
100 m_vasprintf(&str
, fmt
, args
);
103 if (err
->type
== DPKG_MSG_WARN
)
104 warning("%s: %s", str
, err
->str
);
106 ohshit("%s: %s", str
, err
->str
);
112 dpkg_error_move(struct dpkg_error
*dst
, struct dpkg_error
*src
)
114 dst
->type
= src
->type
;
115 src
->type
= DPKG_MSG_NONE
;
121 dpkg_error_destroy(struct dpkg_error
*err
)
123 err
->type
= DPKG_MSG_NONE
;