diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-20 12:54:23 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-06 23:01:30 -0600 |
commit | 38ae81e7b4fbf43217a25b0732ca7ee3a1d34db7 (patch) | |
tree | 9445bc2850d086c2aea6865214feef237ec173de /libmisc/error.c | |
parent | c8b62bcbb5e18b3ca643acedee7fda0c45460b62 (diff) |
libmisc: Add error.h
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), ")"); +} |