aboutsummaryrefslogtreecommitdiff
path: root/src/util/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/buffer.c')
-rw-r--r--src/util/buffer.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/util/buffer.c b/src/util/buffer.c
index dabf630c7..c865f6307 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -130,7 +130,26 @@ GNUNET_buffer_reap_str (struct GNUNET_Buffer *buf)
130 buf->mem[buf->position++] = '\0'; 130 buf->mem[buf->position++] = '\0';
131 } 131 }
132 res = buf->mem; 132 res = buf->mem;
133 *buf = (struct GNUNET_Buffer) { 0 }; 133 memset (buf, 0, sizeof (struct GNUNET_Buffer));
134 return res;
135}
136
137
138/**
139 * Clear the buffer and return its contents.
140 * The caller is responsible to eventually #GNUNET_free
141 * the returned data.
142 *
143 * @param buf the buffer to reap the contents from
144 * @param size where to store the size of the returned data
145 * @returns the data contained in the string
146 */
147void *
148GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size)
149{
150 *size = buf->position;
151 void *res = buf->mem;
152 memset (buf, 0, sizeof (struct GNUNET_Buffer));
134 return res; 153 return res;
135} 154}
136 155
@@ -144,7 +163,7 @@ void
144GNUNET_buffer_clear (struct GNUNET_Buffer *buf) 163GNUNET_buffer_clear (struct GNUNET_Buffer *buf)
145{ 164{
146 GNUNET_free_non_null (buf->mem); 165 GNUNET_free_non_null (buf->mem);
147 *buf = (struct GNUNET_Buffer) { 0 }; 166 memset (buf, 0, sizeof (struct GNUNET_Buffer));
148} 167}
149 168
150 169