mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
common: New function get_membuf_shrink.
* common/membuf.c (get_membuf_shrink): New.
This commit is contained in:
parent
55c3e5f448
commit
556562086a
@ -170,6 +170,31 @@ get_membuf (membuf_t *mb, size_t *len)
|
||||
}
|
||||
|
||||
|
||||
/* Same as get_membuf but shrinks the reallocated space to the
|
||||
required size. */
|
||||
void *
|
||||
get_membuf_shrink (membuf_t *mb, size_t *len)
|
||||
{
|
||||
void *p, *pp;
|
||||
size_t dummylen;
|
||||
|
||||
if (!len)
|
||||
len = &dummylen;
|
||||
|
||||
p = get_membuf (mb, &len);
|
||||
if (!p)
|
||||
return NULL;
|
||||
if (len)
|
||||
{
|
||||
pp = xtryrealloc (p, len);
|
||||
if (pp)
|
||||
p = pp;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/* Peek at the membuf MB. On success a pointer to the buffer is
|
||||
returned which is valid until the next operation on MB. If LEN is
|
||||
not NULL the current LEN of the buffer is stored there. On error
|
||||
|
@ -57,6 +57,7 @@ void put_membuf_str (membuf_t *mb, const char *string);
|
||||
void put_membuf_printf (membuf_t *mb, const char *format,
|
||||
...) JNLIB_GCC_A_PRINTF(2,3);
|
||||
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);
|
||||
|
||||
#endif /*GNUPG_COMMON_MEMBUF_H*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user