2024-06-23 16:27:51 +02:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2024-06-27 01:21:25 +02:00
|
|
|
#include <stdio.h>
|
2024-06-23 16:27:51 +02:00
|
|
|
|
|
|
|
#define rb_size_t size_t
|
|
|
|
#include "ringbuf.h"
|
|
|
|
|
2024-06-27 00:05:49 +02:00
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2024-06-23 16:27:51 +02:00
|
|
|
struct RingBuf rb;
|
|
|
|
rb_init(&rb, 10, malloc, sizeof(int));
|
|
|
|
|
2024-06-30 23:57:08 +02:00
|
|
|
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
2024-06-30 05:08:42 +02:00
|
|
|
|
2024-06-30 23:57:08 +02:00
|
|
|
int ok = WriteOk; // Assume we can write
|
|
|
|
for(int i = 0; i < 10 && ok == WriteOk; i++) {
|
|
|
|
ok = rb_push_back(&rb, &arr[i], memcpy);
|
|
|
|
}
|
2024-06-30 05:08:42 +02:00
|
|
|
|
|
|
|
int d;
|
2024-06-30 23:57:08 +02:00
|
|
|
while(rb_pop_front(&rb, &d) == ReadOk) {
|
|
|
|
printf("Data: %d\n", d);
|
|
|
|
}
|
2024-06-27 01:21:25 +02:00
|
|
|
|
|
|
|
rb_destroy(&rb, free);
|
2024-06-23 16:27:51 +02:00
|
|
|
|
|
|
|
return 0;
|
2024-06-27 00:05:49 +02:00
|
|
|
}
|