diff --git a/example/ex.c b/example/ex.c new file mode 100644 index 0000000..b7a2a06 --- /dev/null +++ b/example/ex.c @@ -0,0 +1,68 @@ +#include +#include +#include + +int main(int argc, char **argv) { + struct ring_t buf; + struct ring_t *res = ring_new(&buf, 20); + + if(res == NULL) { + fprintf(stderr, "uh oh\n"); + return 1; + } + + char *write_str = strdup("abcdefghijklmnopqrstuvwxyz"); + size_t len = ring_write(&buf, write_str, 26); + + if(len != 6) { + fprintf(stderr, "what happened? (%zu)\n", len); + return 1; + } + + len = 5; + char *read_str = ring_read(&buf, &len); + + if(len) { + fprintf(stderr, "that's not good (%zu)\n", len); + return 1; + } + + printf("first read: %s\n", read_str); + len = ring_write(&buf, write_str + 20, 6); + + if(len != 1) { + fprintf(stderr, "you should probably fix this\n"); + return 1; + } + + len = 10; + read_str = ring_read(&buf, &len); + + if(len) { + fprintf(stderr, "hmmmm\n"); + return 1; + } + + printf("second read: %s\n", read_str); + + len = ring_write(&buf, write_str + 25, 1); + len = ring_write(&buf, write_str, 26); + + printf("didn't write %zu characters\n", len); + + len = 20; + read_str = ring_read(&buf, &len); + + printf("final read (20): %s\n", read_str); + ring_del(&buf); + + return 0; +} + +/* +struct ring_t *ring_new(struct ring_t *buf, size_t len); +size_t ring_write(struct ring_t *buf, char *str, size_t orig_len); +char *ring_read(struct ring_t *buf, size_t *len); +char *ring_readln(struct ring_t *buf, size_t *len); +void ring_del(struct ring_t *buf); +*/