From da391022160804785dad7d53b464e0448ab8aba0 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 20 Dec 2021 17:05:14 +0100 Subject: common: Add set_membuf_err. * common/membuf.c (set_membuf_err): New. --- common/membuf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'common/membuf.c') 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; + } +} -- cgit v1.2.3