summaryrefslogtreecommitdiff
path: root/buffer.h
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2002-11-21 23:27:13 +0100
committerNiels Möller <nisse@lysator.liu.se>2002-11-21 23:27:13 +0100
commitbc63438c23cae6d876b4c424cfbe5f37b3468475 (patch)
treef758ca351ac546d198926880e60ac03878004050 /buffer.h
parente82d0a9587aa6b3da2068ac3542e4896b9068a7f (diff)
downloadnettle-bc63438c23cae6d876b4c424cfbe5f37b3468475.tar.gz
* buffer.c (nettle_buffer_grow): New function, replacing
grow_realloc. (nettle_buffer_clear): Rewritten to use buffer->realloc. * buffer.h (struct nettle_buffer): REplaced the GROW function pointer with a nettle_realloc_func pointer and a void (NETTLE_BUFFER_GROW): Deleted macro, use function instead. Rev: src/nettle/buffer.c:1.2 Rev: src/nettle/buffer.h:1.3
Diffstat (limited to 'buffer.h')
-rw-r--r--buffer.h20
1 files changed, 8 insertions, 12 deletions
diff --git a/buffer.h b/buffer.h
index bddab29c..c153839e 100644
--- a/buffer.h
+++ b/buffer.h
@@ -26,20 +26,16 @@
#ifndef NETTLE_BUFFER_H_INCLUDED
#define NETTLE_BUFFER_H_INCLUDED
-#include <inttypes.h>
+#include "realloc.h"
struct nettle_buffer
{
uint8_t *contents;
/* Allocated size */
unsigned alloc;
-
- /* If GROW is NULL, no reallocation is done. Otherwise, it should be
- * a function that reallocates the contents to at least the size SIZE
- * + LENGTH. It can return 0 if allocation fails. Furthermore, if
- * GROW is called with LENGTH = 0, it should deallocate the buffer
- * space. */
- int (*grow)(struct nettle_buffer *buffer, unsigned length);
+
+ nettle_realloc_func *realloc;
+ void *realloc_ctx;
/* Current size */
unsigned size;
@@ -57,12 +53,12 @@ nettle_buffer_init_size(struct nettle_buffer *buffer,
void
nettle_buffer_clear(struct nettle_buffer *buffer);
-/* FIXME: Put the comparison buffer->size + length > buffer->alloc
- * inside this macro. */
-#define NETTLE_BUFFER_GROW(o, l) ((o)->grow && (o)->grow((o), l))
+int
+nettle_buffer_grow(struct nettle_buffer *buffer,
+ unsigned length);
#define NETTLE_BUFFER_PUTC(buffer, c) \
-( (((buffer)->size < (buffer)->alloc) || NETTLE_BUFFER_GROW((buffer), 1)) \
+( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
&& ((buffer)->contents[(buffer)->size++] = (c), 1) )
int