diff options
Diffstat (limited to 'libmisc/error.c')
-rw-r--r-- | libmisc/error.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libmisc/error.c b/libmisc/error.c new file mode 100644 index 0000000..dfe4e80 --- /dev/null +++ b/libmisc/error.c @@ -0,0 +1,26 @@ +/* libmisc/error.c - Go-esque errors + * + * Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include <libmisc/error.h> + +const char *error_msg(error err) { + return (err._msg && err._msg[0]) + ? err._msg + : _errnum_str_msg(err.num); +} + +void error_cleanup(error *errptr) { + if (!errptr) + return; + if (errptr->_msg) + free(errptr->_msg); + errptr->num = E_NOERROR; + errptr->_msg = NULL; +} + +void fmt_print_error(lo_interface fmt_dest w, error err) { + fmt_print(w, (str, error_msg(err)), " (", _errnum_str_sym(err.num), ")"); +} |