forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_libringbuffer.c
35 lines (33 loc) · 993 Bytes
/
test_libringbuffer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/******************************************************************************
* Copyright (C) 2014-2015
* file: test_libringbuffer.c
* author: gozfree <[email protected]>
* created: 2016-06-29 11:42:50
* updated: 2016-06-29 11:42:50
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libringbuffer.h"
int foo()
{
struct ringbuffer *rb = rb_create(1024);
const char *tmp = "hello world";
ssize_t ret = rb_write(rb, tmp, strlen(tmp));
printf("rb_write len=%zu\n", ret);
ret = rb_write(rb, tmp, strlen(tmp));
printf("rb_write len=%zu\n", ret);
char tmp2[9];
memset(tmp2, 0, sizeof(tmp2));
rb_read(rb, tmp2, sizeof(tmp2)-1);
printf("rb_read str=%s\n", tmp2);
memset(tmp2, 0, sizeof(tmp2));
rb_read(rb, tmp2, sizeof(tmp2)-1);
printf("rb_read str=%s\n", tmp2);
return 0;
}
int main(int argc, char **argv)
{
foo();
return 0;
}