rbuf: adapt to work on ccan/membuf.
[ccan] / ccan / rbuf / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * rbuf - buffered I/O input primitive.
7  *
8  * This code is like stdio, only simpler and more transparent to the user.
9  *
10  * Author: Rusty Russell <rusty@rustcorp.com.au>
11  * License: BSD-MIT
12  *
13  * Example:
14  *      #include <ccan/rbuf/rbuf.h>
15  *      #include <ccan/err/err.h>
16  *      #include <stdlib.h>
17  *      #include <unistd.h>
18  *
19  *      // Dumb demo program to replace ' ' with '*'.
20  *      int main(int argc, char *argv[])
21  *      {
22  *              struct rbuf in;
23  *              char *word;
24  *
25  *              if (argv[1]) {
26  *                      if (!rbuf_open(&in, argv[1], NULL, 0, membuf_realloc))
27  *                              err(1, "Failed opening %s", argv[1]);
28  *              } else
29  *                      rbuf_init(&in, STDIN_FILENO, NULL, 0, membuf_realloc);
30  *
31  *              while ((word = rbuf_read_str(&in, ' ')) != NULL)
32  *                      printf("%s*", word);
33  *
34  *              if (errno)
35  *                      err(1, "Reading %s", argv[1] ? argv[1] : "<stdin>");
36  *
37  *              // Free the buffer, just because we can.
38  *              free(rbuf_cleanup(&in));
39  *              return 0;
40  *      }
41  */
42 int main(int argc, char *argv[])
43 {
44         /* Expect exactly one argument */
45         if (argc != 2)
46                 return 1;
47
48         if (strcmp(argv[1], "depends") == 0) {
49                 printf("ccan/membuf\n");
50                 return 0;
51         }
52
53         return 1;
54 }