X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fmembuf%2F_info;fp=ccan%2Fmembuf%2F_info;h=bdcbce2b2f205724d39a6783e212eee2da3a7e83;hp=0000000000000000000000000000000000000000;hb=86d30436820cacfc872de2ba518dd0b54b544647;hpb=a8722345053b7cd860499aa31fd6bb414c120cc8;ds=sidebyside diff --git a/ccan/membuf/_info b/ccan/membuf/_info new file mode 100644 index 00000000..bdcbce2b --- /dev/null +++ b/ccan/membuf/_info @@ -0,0 +1,51 @@ +#include "config.h" +#include +#include + +/** + * membuf - simple linear memory buffer routines. + * + * It's common to want a linear memory buffer, where you can get memory on + * the end, and consume memory from the start. The details of actually + * when to enlarge or move the buffer are slightly nontrivial, so they're + * encapsulated here. + * + * License: BSD-MIT + * Author: Rusty Russell + * + * Example: + * #include + * #include + * #include + * + * // Given "hello world" outputs helloworld + * // Given "hello there world" outputs hellothereworld + * int main(int argc, char *argv[]) + * { + * MEMBUF(char) charbuf; + * + * membuf_init(&charbuf, malloc(10), 10, membuf_realloc); + * + * for (int i = 1; i < argc; i++) + * strcpy(membuf_add(&charbuf, strlen(argv[i])), argv[i]); + * + * // This is dumb, we could do all at once, but shows technique. + * while (membuf_num_elems(&charbuf) > 0) + * printf("%c", *(char *)membuf_consume(&charbuf, 1)); + * printf("\n"); + * return 0; + * } + */ +int main(int argc, char *argv[]) +{ + /* Expect exactly one argument */ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + printf("ccan/tcon\n"); + return 0; + } + + return 1; +}