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