diff options
| -rw-r--r-- | buffer.c | 12 | ||||
| -rw-r--r-- | buffer.h | 6 | ||||
| -rw-r--r-- | test/core/Makefile | 2 | ||||
| -rw-r--r-- | test/core/buffer-test.c | 10 |
4 files changed, 7 insertions, 23 deletions
@@ -67,7 +67,7 @@ bool buffer_remove(Buffer *buf, size_t pos, size_t len) { return true; } -bool buffer_insert(Buffer *buf, size_t pos, const void *data, size_t len) { +static bool buffer_insert(Buffer *buf, size_t pos, const void *data, size_t len) { if (pos > buf->len) return false; if (len == 0) @@ -84,7 +84,7 @@ bool buffer_insert(Buffer *buf, size_t pos, const void *data, size_t len) { bool buffer_insert0(Buffer *buf, size_t pos, const char *data) { if (pos == 0) - return buffer_prepend0(buf, data); + return buffer_insert(buf, 0, data, strlen(data) + (buf->len == 0)); if (pos == buf->len) return buffer_append0(buf, data); return buffer_insert(buf, pos, data, strlen(data)); @@ -103,14 +103,6 @@ bool buffer_append0(Buffer *buf, const char *data) { return ret; } -bool buffer_prepend(Buffer *buf, const void *data, size_t len) { - return buffer_insert(buf, 0, data, len); -} - -bool buffer_prepend0(Buffer *buf, const char *data) { - return buffer_prepend(buf, data, strlen(data) + (buf->len == 0)); -} - static bool buffer_vappendf(Buffer *buf, const char *fmt, va_list ap) { va_list ap_save; va_copy(ap_save, ap); @@ -34,18 +34,12 @@ bool buffer_put(Buffer*, const void *data, size_t len); bool buffer_put0(Buffer*, const char *data); /** Remove ``len`` bytes starting at ``pos``. */ bool buffer_remove(Buffer*, size_t pos, size_t len); -/** Insert ``len`` bytes of ``data`` at ``pos``. */ -bool buffer_insert(Buffer*, size_t pos, const void *data, size_t len); /** Insert NUL-terminated data at pos. */ bool buffer_insert0(Buffer*, size_t pos, const char *data); /** Append further content to the end. */ bool buffer_append(Buffer*, const void *data, size_t len); /** Append NUL-terminated data. */ bool buffer_append0(Buffer*, const char *data); -/** Insert ``len`` bytes of ``data`` at the start. */ -bool buffer_prepend(Buffer*, const void *data, size_t len); -/** Insert NUL-terminated data at the start. */ -bool buffer_prepend0(Buffer*, const char *data); /** Append formatted buffer content, ensures NUL termination on success. */ bool buffer_appendf(Buffer*, const char *fmt, ...) __attribute__((format(printf, 2, 3))); /** Return length of a buffer without trailing NUL byte. */ diff --git a/test/core/Makefile b/test/core/Makefile index 19991de..b0284b8 100644 --- a/test/core/Makefile +++ b/test/core/Makefile @@ -20,7 +20,7 @@ text-test: config.h text-test.c ../../text.c ../../text-common.c ../../text-io.c buffer-test: config.h buffer-test.c ../../buffer.c @echo Compiling $@ binary - @${CC} ${CFLAGS} ${CFLAGS_STD} ${CFLAGS_LIBC} ${CFLAGS_EXTRA} ${filter %.c, $^} ${SRC} ${LDFLAGS} -o $@ + @${CC} ${CFLAGS} ${CFLAGS_STD} ${CFLAGS_LIBC} ${CFLAGS_EXTRA} buffer-test.c ${SRC} ${LDFLAGS} -o $@ map-test: config.h map-test.c ../../map.c @echo Compiling $@ binary diff --git a/test/core/buffer-test.c b/test/core/buffer-test.c index f3b2dad..8034ac4 100644 --- a/test/core/buffer-test.c +++ b/test/core/buffer-test.c @@ -4,7 +4,7 @@ #include <stdlib.h> #include <string.h> #include "tap.h" -#include "buffer.h" +#include "buffer.c" static bool compare(Buffer *buf, const char *data, size_t len) { return buf->len == len && (len == 0 || memcmp(buf->data, data, buf->len) == 0); @@ -32,8 +32,7 @@ int main(int argc, char *argv[]) { ok(buffer_put0(&buf, "") && compare0(&buf, ""), "Put empty string"); ok(buffer_put0(&buf, "bar") && compare0(&buf, "bar"), "Put string"); - ok(buffer_prepend0(&buf, "foo") && compare0(&buf, "foobar"), "Prepend string"); - ok(buffer_append0(&buf, "baz") && compare0(&buf, "foobarbaz"), "Append string"); + ok(buffer_append0(&buf, "baz") && compare0(&buf, "barbaz"), "Append string"); buffer_release(&buf); ok(buf.data == NULL && buf.len == 0 && buf.size == 0, "Release"); @@ -50,10 +49,9 @@ int main(int argc, char *argv[]) { ok(buffer_put(&buf, "foo", 0) && compare(&buf, "", 0), "Put zero length data"); ok(buffer_put(&buf, "bar", 3) && compare(&buf, "bar", 3), "Put data"); - ok(buffer_prepend(&buf, "foo\0", 4) && compare(&buf, "foo\0bar", 7), "Prepend data"); - ok(buffer_append(&buf, "\0baz", 4) && compare(&buf, "foo\0bar\0baz", 11), "Append data"); + ok(buffer_append(&buf, "\0baz", 4) && compare(&buf, "bar\0baz", 7), "Append data"); - ok(buffer_grow(&buf, cap+1) && compare(&buf, "foo\0bar\0baz", 11) && buf.size >= cap+1, "Grow"); + ok(buffer_grow(&buf, cap+1) && compare(&buf, "bar\0baz", 7) && buf.size >= cap+1, "Grow"); buf.len = 0; skip_if(TIS_INTERPRETER, 1, "vsnprintf not supported") { |
