]> git.ozlabs.org Git - ccan/blob - ccan/grab_file/_info
rbtree: add tests (which currently fail)
[ccan] / ccan / grab_file / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * 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/grab_file/grab_file.h>
15  *      #include <ccan/talloc/talloc.h> // For talloc_free()
16  *
17  *      int main(int argc, char *argv[])
18  *      {
19  *              size_t len;
20  *              char *file;
21  *
22  *              file = grab_file(NULL, argv[1], &len);
23  *              if (!file)
24  *                      err(1, "Could not read file %s", argv[1]);
25  *              if (strlen(file) != len)
26  *                      printf("File contains NUL characters\n");
27  *              else if (len == 0)
28  *                      printf("File contains nothing\n");
29  *              else if (strchr(file, '\n'))
30  *                      printf("File contains multiple lines\n");
31  *              else
32  *                      printf("File contains one line\n");
33  *              talloc_free(file);
34  *
35  *              return 0;
36  *      }
37  *
38  * License: LGPL (2 or any later version)
39  * Author: Rusty Russell <rusty@rustcorp.com.au>
40  */
41 int main(int argc, char *argv[])
42 {
43         if (argc != 2)
44                 return 1;
45
46         if (strcmp(argv[1], "depends") == 0) {
47                 printf("ccan/str_talloc\n"); /* Needed for tests. */
48                 printf("ccan/talloc\n");
49                 printf("ccan/noerr\n");
50                 return 0;
51         }
52
53         return 1;
54 }