31 lines
541 B
C
31 lines
541 B
C
/* SPDX-License-Identifier: MIT */
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#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
|
|
for(int i = 0; i < 10 && ok == WriteOk; i++) {
|
|
ok = rb_push_back(&rb, &arr[i], memcpy);
|
|
}
|
|
|
|
int d;
|
|
while(rb_pop_front(&rb, &d) == ReadOk) {
|
|
printf("Data: %d\n", d);
|
|
}
|
|
|
|
rb_destroy(&rb, free);
|
|
|
|
return 0;
|
|
}
|