diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-11 22:24:21 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-12 02:32:42 -0600 |
commit | f014bc44c7617650ed9f957bada6281db8a35d75 (patch) | |
tree | e8c539da354cf86ee8901bc95ead4b844b2d73ec /libmisc | |
parent | 2fb446c886c4f4d6750abf4778cdff4775786f9a (diff) |
libmisc: error.h: Add error_dup()
Diffstat (limited to 'libmisc')
-rw-r--r-- | libmisc/error.c | 9 | ||||
-rw-r--r-- | libmisc/include/libmisc/error.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libmisc/error.c b/libmisc/error.c index dfe4e80..345755c 100644 --- a/libmisc/error.c +++ b/libmisc/error.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +#include <string.h> /* for strdup() */ + #include <libmisc/error.h> const char *error_msg(error err) { @@ -12,6 +14,13 @@ const char *error_msg(error err) { : _errnum_str_msg(err.num); } +error error_dup(error err) { + return (error){ + .num = err.num, + ._msg = err._msg ? strdup(err._msg) : NULL, + }; +} + void error_cleanup(error *errptr) { if (!errptr) return; diff --git a/libmisc/include/libmisc/error.h b/libmisc/include/libmisc/error.h index 4110626..c9b53dd 100644 --- a/libmisc/include/libmisc/error.h +++ b/libmisc/include/libmisc/error.h @@ -136,6 +136,7 @@ typedef struct { #define ERROR_IS_NULL(err) ((err).num == 0 && (err)._msg == NULL) const char *error_msg(error err); +error error_dup(error err); void error_cleanup(error *errptr); void fmt_print_error(lo_interface fmt_dest w, error err); |