]> git.ozlabs.org Git - ccan/blob - ccan/membuf/_info
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / membuf / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * membuf - simple linear memory buffer routines.
7  *
8  * It's common to want a linear memory buffer, where you can get memory on
9  * the end, and consume memory from the start.  The details of actually
10  * when to enlarge or move the buffer are slightly nontrivial, so they're
11  * encapsulated here.
12  *
13  * License: BSD-MIT
14  * Author: Rusty Russell <rusty@rustcorp.com.au>
15  *
16  * Example:
17  * #include <ccan/membuf/membuf.h>
18  * #include <string.h>
19  * #include <stdio.h>
20  *
21  * // Given "hello world" outputs helloworld
22  * // Given "hello there world" outputs hellothereworld
23  * int main(int argc, char *argv[])
24  * {
25  *      MEMBUF(char) charbuf;
26  *
27  *      membuf_init(&charbuf, malloc(10), 10, membuf_realloc);
28  *
29  *      for (int i = 1; i < argc; i++)
30  *              strcpy(membuf_add(&charbuf, strlen(argv[i])), argv[i]);
31  *
32  *      // This is dumb, we could do all at once, but shows technique.
33  *      while (membuf_num_elems(&charbuf) > 0)
34  *              printf("%c", *(char *)membuf_consume(&charbuf, 1));
35  *      printf("\n");
36  *      return 0;
37  * }
38  */
39 int main(int argc, char *argv[])
40 {
41         /* Expect exactly one argument */
42         if (argc != 2)
43                 return 1;
44
45         if (strcmp(argv[1], "depends") == 0) {
46                 printf("ccan/tcon\n");
47                 return 0;
48         }
49
50         return 1;
51 }