summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-03-03 22:19:15 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-03-03 22:19:15 +0100
commit14fb4ab4a19bbb281f614ef93a009a07e86ebf14 (patch)
tree1a640cecf893995ae12c7b5ed7b16b4940e69762 /src
parentb12cafd6f8fe7fc9fd12fc32e212daa2de09a38a (diff)
buffer: simplify api removing booleans and make fixed static
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c18
-rw-r--r--src/buffer.h5
2 files changed, 7 insertions, 16 deletions
diff --git a/src/buffer.c b/src/buffer.c
index dde1d90..a3ee649 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,15 +1,13 @@
#include "buffer.h"
#include <string.h>
#include <malloc.h>
+#include <assert.h>
-bool init_growable_buffer(growable_buffer *buffer) {
+void init_growable_buffer(growable_buffer *buffer) {
buffer->size = GROW_SIZE;
buffer->used = 0;
buffer->content = malloc(GROW_SIZE);
- if (!buffer->content) {
- return false;
- }
- return true;
+ assert( buffer->content != 0 );
}
char* grow_growable_buffer(growable_buffer *buffer, size_t at_least) {
@@ -46,14 +44,8 @@ void free_growable_buffer(growable_buffer *buffer) {
-bool init_fixed_buffer(fixed_buffer *buffer, char *orig) {
+void init_fixed_buffer(fixed_buffer *buffer, char *orig) {
buffer->content = orig;
buffer->size = strlen(orig);
- return buffer->content != NULL;
-}
-
-void free_fixed_buffer(fixed_buffer *buffer) {
- free(buffer->content);
- buffer->content = NULL;
- buffer->size = 0;
+ assert( buffer->content != NULL );
}
diff --git a/src/buffer.h b/src/buffer.h
index 67e1bf7..bbcda9a 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -10,7 +10,7 @@ typedef struct {
size_t size;
} growable_buffer;
-bool init_growable_buffer(growable_buffer *buffer);
+void init_growable_buffer(growable_buffer *buffer);
char *grow_growable_buffer(growable_buffer *buffer, size_t at_least);
void append_growable_buffer(growable_buffer *buffer, char* content, size_t length);
void free_growable_buffer(growable_buffer *buffer);
@@ -21,7 +21,6 @@ typedef struct {
size_t size;
} fixed_buffer;
-bool init_fixed_buffer(fixed_buffer *buffer, char *orig);
-void free_fixed_buffer(fixed_buffer *buffer);
+void init_fixed_buffer(fixed_buffer *buffer, char *orig);
#endif // BUFFER_H