From a5c5ecd64b66220692f058c1ae22579f08d88c48 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 2 Jul 2024 08:39:31 +0200 Subject: [PATCH] Bug................................... --- driver.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/driver.c b/driver.c index 36f7bb5..3d90144 100644 --- a/driver.c +++ b/driver.c @@ -11,16 +11,52 @@ int main(void) { struct RingBuf rb; + int d; rb_init(&rb, 10, malloc, sizeof(int)); + const int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Single writes + printf("\n=== Single writes ===\n\n"); + + int idx = 0; + while (idx < 5) { + if(rb_push_back(&rb, &arr[idx], memcpy) != WriteOk) { + printf("Failed to write data to buffer...\n"); + } + idx++; + } + + // Pop the last n elements + for(int a = 0; a < 1; a++) { + if(rb_pop_front(&rb, &d, memcpy) != ReadOk) { + printf("Failed to read data from buffer...\n"); + } + printf("Data: %d\n", d); + } + + printf("idx: %d\n", idx); + + // Push the rest + while (rb_push_back(&rb, &arr[idx], memcpy) == WriteOk) { + printf("Wrote: %d\n", arr[idx]); + idx++; + } + + printf("Data: ["); + while(rb_pop_front(&rb, &d, memcpy) == ReadOk) + printf("%d,", d); + printf("\b]\n"); + + // Multiple writes + printf("\n=== Multiple writes ===\n\n"); + + rb_clear(&rb); int ok = WriteOk; // Assume we can write if(rb_push_many(&rb, arr, memcpy, 8) != WriteOk) { printf("Failed to write data to buffer...\n"); } - int d; printf("Data: ["); while(rb_pop_front(&rb, &d, memcpy) == ReadOk) printf("%d,", d);