diff options
Diffstat (limited to 'lib/stream.c')
| -rw-r--r-- | lib/stream.c | 41 |
1 files changed, 22 insertions, 19 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) |
