GNUnet  0.11.x
gnunet_buffer_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #ifndef GNUNET_BUFFER_LIB_H
28 #define GNUNET_BUFFER_LIB_H
29 
40 {
44  size_t capacity;
45 
49  size_t position;
50 
54  char *mem;
55 
59  int warn_grow;
60 };
61 
62 
72 void
74 
75 
82 void
84 
85 
96 void
97 GNUNET_buffer_write (struct GNUNET_Buffer *buf, const char *data, size_t len);
98 
99 
108 void
109 GNUNET_buffer_write_str (struct GNUNET_Buffer *buf, const char *str);
110 
111 
120 void
121 GNUNET_buffer_write_path (struct GNUNET_Buffer *buf, const char *str);
122 
123 
134 void
135 GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt, ...);
136 
137 
148 void
149 GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf, const char *fmt, va_list
150  args);
151 
152 
163 char *
165 
166 
172 void
174 
175 
176 #endif
size_t capacity
Capacity of the buffer.
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition: buffer.c:117
void GNUNET_buffer_write(struct GNUNET_Buffer *buf, const char *data, size_t len)
Write bytes to the buffer.
Definition: buffer.c:83
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...)
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
Definition: buffer.c:184
void GNUNET_buffer_ensure_remaining(struct GNUNET_Buffer *buf, size_t n)
Make sure that at least n bytes remaining in the buffer.
Definition: buffer.c:54
void GNUNET_buffer_write_path(struct GNUNET_Buffer *buf, const char *str)
Write a path component to a buffer, ensuring that there is exactly one slash between the previous con...
Definition: buffer.c:155
static char buf[2048]
char * mem
Backing memory.
size_t position
Current write position.
void GNUNET_buffer_prealloc(struct GNUNET_Buffer *buf, size_t capacity)
Initialize a buffer with the given capacity.
Definition: buffer.c:35
void GNUNET_buffer_clear(struct GNUNET_Buffer *buf)
Free the backing memory of the given buffer.
Definition: buffer.c:139
Common buffer management functions.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition: buffer.c:98
uint32_t data
The data value.
void GNUNET_buffer_write_vfstr(struct GNUNET_Buffer *buf, const char *fmt, va_list args)
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
Definition: buffer.c:205
int warn_grow
Log a warning if the buffer is grown over its initially allocated capacity.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...