ringbuf/driver.c

30 lines
461 B
C
Raw Normal View History

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-27 00:05:49 +02:00
int data[] = { 1, 2, 3, 4, 5 };
2024-06-23 16:27:51 +02:00
rb_push(&rb, (void **)data, 5, memcpy);
2024-06-27 01:21:25 +02:00
int dest[5];
rb_read(&rb, (void *)dest, 5);
for (int i = 0; i < 5; i++) {
printf("Data: %d\n", dest[i]);
}
rb_destroy(&rb, free);
2024-06-23 16:27:51 +02:00
return 0;
2024-06-27 00:05:49 +02:00
}