mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-05 12:31:50 +01:00
common: Add put_membuf_printf.
* common/membuf.c (put_membuf_printf): New. -- This is just a convenience function for easier code readability. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
2c9613f326
commit
159d42ee6a
@ -1,5 +1,6 @@
|
|||||||
/* membuf.c - A simple implementation of a dynamic buffer.
|
/* membuf.c - A simple implementation of a dynamic buffer.
|
||||||
* Copyright (C) 2001, 2003, 2009, 2011 Free Software Foundation, Inc.
|
* Copyright (C) 2001, 2003, 2009, 2011 Free Software Foundation, Inc.
|
||||||
|
* Copyright (C) 2013 Werner Koch
|
||||||
*
|
*
|
||||||
* This file is part of GnuPG.
|
* This file is part of GnuPG.
|
||||||
*
|
*
|
||||||
@ -30,6 +31,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "membuf.h"
|
#include "membuf.h"
|
||||||
|
|
||||||
@ -122,6 +124,26 @@ put_membuf_str (membuf_t *mb, const char *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
put_membuf_printf (membuf_t *mb, const char *format, ...)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
va_list arg_ptr;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
va_start (arg_ptr, format);
|
||||||
|
rc = estream_vasprintf (&buf, format, arg_ptr);
|
||||||
|
if (rc < 0)
|
||||||
|
mb->out_of_core = errno ? errno : ENOMEM;
|
||||||
|
va_end (arg_ptr);
|
||||||
|
if (rc >= 0)
|
||||||
|
{
|
||||||
|
put_membuf (mb, buf, strlen (buf));
|
||||||
|
xfree (buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
get_membuf (membuf_t *mb, size_t *len)
|
get_membuf (membuf_t *mb, size_t *len)
|
||||||
{
|
{
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#ifndef GNUPG_COMMON_MEMBUF_H
|
#ifndef GNUPG_COMMON_MEMBUF_H
|
||||||
#define GNUPG_COMMON_MEMBUF_H
|
#define GNUPG_COMMON_MEMBUF_H
|
||||||
|
|
||||||
|
#include "mischelp.h"
|
||||||
|
|
||||||
/* The definition of the structure is private, we only need it here,
|
/* The definition of the structure is private, we only need it here,
|
||||||
so it can be allocated on the stack. */
|
so it can be allocated on the stack. */
|
||||||
struct private_membuf_s
|
struct private_membuf_s
|
||||||
@ -52,6 +54,8 @@ void init_membuf_secure (membuf_t *mb, int initiallen);
|
|||||||
void clear_membuf (membuf_t *mb, size_t amount);
|
void clear_membuf (membuf_t *mb, size_t amount);
|
||||||
void put_membuf (membuf_t *mb, const void *buf, size_t len);
|
void put_membuf (membuf_t *mb, const void *buf, size_t len);
|
||||||
void put_membuf_str (membuf_t *mb, const char *string);
|
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 (membuf_t *mb, size_t *len);
|
||||||
const void *peek_membuf (membuf_t *mb, size_t *len);
|
const void *peek_membuf (membuf_t *mb, size_t *len);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user