summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/stream.c41
-rw-r--r--lib/stream.h20
2 files changed, 36 insertions, 25 deletions
diff --git a/lib/stream.c b/lib/stream.c
index cf9af4d3bb..55e7f64358 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -28,9 +28,9 @@
#include "network.h"
#include "prefix.h"
#include "log.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, STREAM, "Stream")
-DEFINE_MTYPE_STATIC(LIB, STREAM_DATA, "Stream data")
DEFINE_MTYPE_STATIC(LIB, STREAM_FIFO, "Stream FIFO")
/* Tests whether a position is valid */
@@ -100,9 +100,7 @@ struct stream *stream_new(size_t size)
assert(size > 0);
- s = XMALLOC(MTYPE_STREAM, sizeof(struct stream));
-
- s->data = XMALLOC(MTYPE_STREAM_DATA, size);
+ s = XMALLOC(MTYPE_STREAM, sizeof(struct stream) + size);
s->getp = s->endp = 0;
s->next = NULL;
@@ -116,7 +114,6 @@ void stream_free(struct stream *s)
if (!s)
return;
- XFREE(MTYPE_STREAM_DATA, s->data);
XFREE(MTYPE_STREAM, s);
}
@@ -166,27 +163,33 @@ struct stream *stream_dupcat(struct stream *s1, struct stream *s2,
return new;
}
-size_t stream_resize(struct stream *s, size_t newsize)
+size_t stream_resize_inplace(struct stream **sptr, size_t newsize)
{
- uint8_t *newdata;
- STREAM_VERIFY_SANE(s);
+ struct stream *orig = *sptr;
- newdata = XREALLOC(MTYPE_STREAM_DATA, s->data, newsize);
+ STREAM_VERIFY_SANE(orig);
- if (newdata == NULL)
- return s->size;
+ orig = XREALLOC(MTYPE_STREAM, orig, sizeof(struct stream) + newsize);
- s->data = newdata;
- s->size = newsize;
+ orig->size = newsize;
- if (s->endp > s->size)
- s->endp = s->size;
- if (s->getp > s->endp)
- s->getp = s->endp;
+ if (orig->endp > orig->size)
+ orig->endp = orig->size;
+ if (orig->getp > orig->endp)
+ orig->getp = orig->endp;
- STREAM_VERIFY_SANE(s);
+ STREAM_VERIFY_SANE(orig);
- return s->size;
+ *sptr = orig;
+ return orig->size;
+}
+
+size_t __attribute__((deprecated))stream_resize_orig(struct stream *s,
+ size_t newsize)
+{
+ assert("stream_resize: Switch code to use stream_resize_inplace" == NULL);
+
+ return stream_resize_inplace(&s, newsize);
}
size_t stream_get_getp(struct stream *s)
diff --git a/lib/stream.h b/lib/stream.h
index e808f039c6..ef9366e1ae 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -98,14 +98,15 @@
struct stream {
struct stream *next;
- /* Remainder is ***private*** to stream
+ /*
+ * Remainder is ***private*** to stream
* direct access is frowned upon!
* Use the appropriate functions/macros
*/
- size_t getp; /* next get position */
- size_t endp; /* last valid data position */
- size_t size; /* size of data segment */
- unsigned char *data; /* data pointer */
+ size_t getp; /* next get position */
+ size_t endp; /* last valid data position */
+ size_t size; /* size of data segment */
+ unsigned char data[0]; /* data pointer */
};
/* First in first out queue structure. */
@@ -154,7 +155,14 @@ extern struct stream *stream_new(size_t);
extern void stream_free(struct stream *);
extern struct stream *stream_copy(struct stream *, struct stream *src);
extern struct stream *stream_dup(struct stream *);
-extern size_t stream_resize(struct stream *, size_t);
+
+#if CONFDATE > 20190821
+CPP_NOTICE("lib: time to remove stream_resize_orig")
+#endif
+extern size_t stream_resize_orig(struct stream *s, size_t newsize);
+#define stream_resize stream_resize_orig
+extern size_t stream_resize_inplace(struct stream **sptr, size_t newsize);
+
extern size_t stream_get_getp(struct stream *);
extern size_t stream_get_endp(struct stream *);
extern size_t stream_get_size(struct stream *);