#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 */
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;
if (!s)
return;
- XFREE(MTYPE_STREAM_DATA, s->data);
XFREE(MTYPE_STREAM, s);
}
size_t stream_resize_inplace(struct stream **sptr, size_t newsize)
{
- return stream_resize_orig(*sptr, newsize);
-}
+ struct stream *orig = *sptr;
-size_t stream_resize_orig(struct stream *s, size_t newsize)
-{
- uint8_t *newdata;
- STREAM_VERIFY_SANE(s);
+ STREAM_VERIFY_SANE(orig);
- newdata = XREALLOC(MTYPE_STREAM_DATA, s->data, newsize);
+ orig = XREALLOC(MTYPE_STREAM, orig, sizeof(struct stream) + newsize);
- if (newdata == NULL)
- return s->size;
+ orig->size = newsize;
- s->data = newdata;
- s->size = newsize;
+ if (orig->endp > orig->size)
+ orig->endp = orig->size;
+ if (orig->getp > orig->endp)
+ orig->getp = orig->endp;
- if (s->endp > s->size)
- s->endp = s->size;
- if (s->getp > s->endp)
- s->getp = s->endp;
+ STREAM_VERIFY_SANE(orig);
- STREAM_VERIFY_SANE(s);
+ *sptr = orig;
+ return orig->size;
+}
- return s->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)
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. */