cast, str, take, tal/grabfile, tal/str, typesafe_cb: use argc
[ccan] / ccan / tal / grab_file / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * tal/grab_file - file helper routines
7  *
8  * This contains simple functions for getting the contents of a file.
9  *
10  * Example:
11  *      #include <err.h>
12  *      #include <stdio.h>
13  *      #include <string.h>
14  *      #include <ccan/tal/grab_file/grab_file.h>
15  *      #include <ccan/tal/tal.h> // for tal_free
16  *
17  *      int main(int argc, char *argv[])
18  *      {
19  *              char *file;
20  *
21  *              if (argc > 2)
22  *                      err(1, "Takes 0 or 1 arguments");
23  *              file = grab_file(NULL, argv[1]);
24  *              if (!file)
25  *                      err(1, "Could not read file %s", argv[1]);
26  *              if (strlen(file)+1 != tal_count(file))
27  *                      printf("File contains NUL characters\n");
28  *              else if (tal_count(file) == 1)
29  *                      printf("File contains nothing\n");
30  *              else if (strchr(file, '\n'))
31  *                      printf("File contains multiple lines\n");
32  *              else
33  *                      printf("File contains one line\n");
34  *              tal_free(file);
35  *
36  *              return 0;
37  *      }
38  *
39  * License: LGPL (v2.1 or any later version)
40  * Author: Rusty Russell <rusty@rustcorp.com.au>
41  */
42 int main(int argc, char *argv[])
43 {
44         if (argc != 2)
45                 return 1;
46
47         if (strcmp(argv[1], "depends") == 0) {
48                 printf("ccan/tal\n");
49                 printf("ccan/noerr\n");
50                 return 0;
51         }
52         if (strcmp(argv[1], "testdepends") == 0) {
53                 printf("ccan/tal/str\n");
54                 return 0;
55         }
56
57         return 1;
58 }