1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

common: Add set_membuf_err.

* common/membuf.c (set_membuf_err): New.
This commit is contained in:
Werner Koch 2021-12-20 17:05:14 +01:00
parent 038136ea48
commit da39102216
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 13 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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*/