/* SPDX-License-Identifier: MIT */ #include #include #include #define rb_size_t size_t #include "ringbuf.h" int main(void) { struct RingBuf rb; rb_init(&rb, 10, malloc, sizeof(int)); int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int ok = WriteOk; // Assume we can write ok = rb_push_many(&rb, arr, memcpy, 8); int d; while(rb_pop_front(&rb, &d, memcpy) == ReadOk) { printf("Data: %d\n", d); } // Test wrap around rb_push_many(&rb, arr, memcpy, 10); while(rb_pop_front(&rb, &d, memcpy) == ReadOk) { printf("Data: %d\n", d); } // Test clear rb_clear(&rb); if(rb_pop_front(&rb, &d, memcpy) != Empty) { printf("Buffer is not empty after clear...\n"); } rb_destroy(&rb, free); enum WriteResult wr = WriteOk; enum ReadResult rr = ReadOk; printf("Size of wr: %lu bytes.\n", sizeof(wr)); printf("Size of rr: %lu bytes.\n", sizeof(rr)); return 0; }