1 #ifndef CCAN_GRAB_FILE_H
2 #define CCAN_GRAB_FILE_H
3 #include <stdio.h> // For size_t
6 * grab_fd - read all of a file descriptor into memory
7 * @ctx: the context to tallocate from (often NULL)
8 * @fd: the file descriptor to read from
9 * @size: the (optional) size of the file
11 * This function reads from the given file descriptor until no more
12 * input is available. The content is talloced off @ctx, and the size
13 * of the file places in @size if it's non-NULL. For convenience, the
14 * byte after the end of the content will always be NUL.
17 * // Return all of standard input, as lines.
18 * char **read_as_lines(void)
22 * all = grab_fd(NULL, 0, NULL);
25 * lines = strsplit(NULL, all, "\n", NULL);
30 void *grab_fd(const void *ctx, int fd, size_t *size);
33 * grab_file - read all of a file (or stdin) into memory
34 * @ctx: the context to tallocate from (often NULL)
35 * @filename: the file to read (NULL for stdin)
36 * @size: the (optional) size of the file
38 * This function reads from the given file until no more input is
39 * available. The content is talloced off @ctx, and the size of the
40 * file places in @size if it's non-NULL. For convenience, the byte
41 * after the end of the content will always be NUL.
44 * // Return all of a given file, as lines.
45 * char **read_as_lines(const char *filename)
49 * all = grab_file(NULL, filename, NULL);
52 * lines = strsplit(NULL, all, "\n", NULL);
57 void *grab_file(const void *ctx, const char *filename, size_t *size);
58 #endif /* CCAN_GRAB_FILE_H */