3 A bare-bones string stream.
5 Copyright (C) 2002 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 #ifndef NETTLE_BUFFER_H_INCLUDED
35 #define NETTLE_BUFFER_H_INCLUDED
50 nettle_realloc_func *realloc;
56 /* Initializes a buffer that uses plain realloc */
58 nettle_buffer_init(struct nettle_buffer *buffer);
61 nettle_buffer_init_realloc(struct nettle_buffer *buffer,
63 nettle_realloc_func *realloc);
65 /* Initializes a buffer of fix size */
67 nettle_buffer_init_size(struct nettle_buffer *buffer,
68 size_t length, uint8_t *space);
71 nettle_buffer_clear(struct nettle_buffer *buffer);
73 /* Resets the buffer, without freeing the buffer space. */
75 nettle_buffer_reset(struct nettle_buffer *buffer);
78 nettle_buffer_grow(struct nettle_buffer *buffer,
81 #define NETTLE_BUFFER_PUTC(buffer, c) \
82 ( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
83 && ((buffer)->contents[(buffer)->size++] = (c), 1) )
86 nettle_buffer_write(struct nettle_buffer *buffer,
87 size_t length, const uint8_t *data);
89 /* Like nettle_buffer_write, but instead of copying data to the
90 * buffer, it returns a pointer to the area where the caller can copy
91 * the data. The pointer is valid only until the next call that can
92 * reallocate the buffer. */
94 nettle_buffer_space(struct nettle_buffer *buffer,
97 /* Copy the contents of SRC to the end of DST. */
99 nettle_buffer_copy(struct nettle_buffer *dst,
100 const struct nettle_buffer *src);
106 #endif /* NETTLE_BUFFER_H_INCLUDED */