1 /* membuf.h - A simple implementation of a dynamic buffer
2 * Copyright (C) 2001, 2003 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of either
9 * - the GNU Lesser General Public License as published by the Free
10 * Software Foundation; either version 3 of the License, or (at
11 * your option) any later version.
15 * - the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
19 * or both in parallel, as here.
21 * This file is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <https://www.gnu.org/licenses/>.
30 #ifndef GNUPG_COMMON_MEMBUF_H
31 #define GNUPG_COMMON_MEMBUF_H
35 /* The definition of the structure is private, we only need it here,
36 so it can be allocated on the stack. */
37 struct private_membuf_s
45 typedef struct private_membuf_s membuf_t;
47 /* Return the current length of the membuf. */
48 #define get_membuf_len(a) ((a)->len)
49 #define is_membuf_ready(a) ((a)->buf || (a)->out_of_core)
50 #define MEMBUF_ZERO { 0, 0, NULL, 0}
52 void init_membuf (membuf_t *mb, int initiallen);
53 void init_membuf_secure (membuf_t *mb, int initiallen);
54 void clear_membuf (membuf_t *mb, size_t amount);
55 void put_membuf (membuf_t *mb, const void *buf, size_t len);
56 gpg_error_t put_membuf_cb (void *opaque, const void *buf, size_t len);
57 void put_membuf_str (membuf_t *mb, const char *string);
58 void put_membuf_printf (membuf_t *mb, const char *format,
59 ...) GPGRT_ATTR_PRINTF(2,3);
60 void *get_membuf (membuf_t *mb, size_t *len);
61 void *get_membuf_shrink (membuf_t *mb, size_t *len);
62 const void *peek_membuf (membuf_t *mb, size_t *len);
64 #endif /*GNUPG_COMMON_MEMBUF_H*/