Coverage Report

Created: 2026-01-10 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnupg/common/membuf.h
Line
Count
Source
1
/* membuf.h - A simple implementation of a dynamic buffer
2
 *  Copyright (C) 2001, 2003 Free Software Foundation, Inc.
3
 *
4
 * This file is part of GnuPG.
5
 *
6
 * This file is free software; you can redistribute it and/or modify
7
 * it under the terms of either
8
 *
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.
12
 *
13
 * or
14
 *
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.
18
 *
19
 * or both in parallel, as here.
20
 *
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.
25
 *
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/>.
28
 */
29
30
#ifndef GNUPG_COMMON_MEMBUF_H
31
#define GNUPG_COMMON_MEMBUF_H
32
33
#include "mischelp.h"
34
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
38
{
39
  size_t len;
40
  size_t size;
41
  char *buf;
42
  int out_of_core;
43
};
44
45
typedef struct private_membuf_s membuf_t;
46
47
/* Return the current length of the membuf.  */
48
#define get_membuf_len(a)  ((a)->len)
49
0
#define is_membuf_ready(a) ((a)->buf || (a)->out_of_core)
50
0
#define MEMBUF_ZERO        { 0, 0, NULL, 0}
51
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);
63
void set_membuf_err (membuf_t *mb, gpg_error_t err);
64
65
#endif /*GNUPG_COMMON_MEMBUF_H*/