diff options
author | Werner Koch <wk@gnupg.org> | 2021-12-20 17:05:14 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2021-12-20 19:34:34 +0100 |
commit | da391022160804785dad7d53b464e0448ab8aba0 (patch) | |
tree | 4be99c6f6d2de6295c5a9697e25ab5b4fe0b75f1 /common | |
parent | wkd: Don't beg for donations (diff) | |
download | gnupg2-da391022160804785dad7d53b464e0448ab8aba0.tar.xz gnupg2-da391022160804785dad7d53b464e0448ab8aba0.zip |
common: Add set_membuf_err.
* common/membuf.c (set_membuf_err): New.
Diffstat (limited to 'common')
-rw-r--r-- | common/membuf.c | 12 | ||||
-rw-r--r-- | common/membuf.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/common/membuf.c b/common/membuf.c index 009fbc336..60491b590 100644 --- a/common/membuf.c +++ b/common/membuf.c @@ -231,3 +231,15 @@ peek_membuf (membuf_t *mb, size_t *len) *len = mb->len; return p; } + +/* To assist using membuf with function returning an error, this + * function sets the membuf into the error state. */ +void +set_membuf_err (membuf_t *mb, gpg_error_t err) +{ + if (!mb->out_of_core) + { + int myerr = gpg_err_code_to_errno (gpg_err_code (err)); + mb->out_of_core = myerr? myerr : EINVAL; + } +} diff --git a/common/membuf.h b/common/membuf.h index 1497bcd04..4b2be1a71 100644 --- a/common/membuf.h +++ b/common/membuf.h @@ -60,5 +60,6 @@ void put_membuf_printf (membuf_t *mb, const char *format, void *get_membuf (membuf_t *mb, size_t *len); void *get_membuf_shrink (membuf_t *mb, size_t *len); const void *peek_membuf (membuf_t *mb, size_t *len); +void set_membuf_err (membuf_t *mb, gpg_error_t err); #endif /*GNUPG_COMMON_MEMBUF_H*/ |