1 /* Licensed under LGPLv2+ - see LICENSE file for details */
2 #ifndef CCAN_GRAB_FILE_H
3 #define CCAN_GRAB_FILE_H
4 #include <stdio.h> // For size_t
7 * grab_fd - read all of a file descriptor into memory
8 * @ctx: the context to tallocate from (often NULL)
9 * @fd: the file descriptor to read from
10 * @size: the (optional) size of the file
12 * This function reads from the given file descriptor until no more
13 * input is available. The content is talloced off @ctx, and the size
14 * of the file places in @size if it's non-NULL. For convenience, the
15 * byte after the end of the content will always be NUL.
18 * // Return the first line.
19 * static char *read_stdin_firstline(void)
23 * all = grab_fd(NULL, 0, NULL);
26 * nl = strchr(all, '\n');
32 void *grab_fd(const void *ctx, int fd, size_t *size);
35 * grab_file - read all of a file (or stdin) into memory
36 * @ctx: the context to tallocate from (often NULL)
37 * @filename: the file to read (NULL for stdin)
38 * @size: the (optional) size of the file
40 * This function reads from the given file until no more input is
41 * available. The content is talloced off @ctx, and the size of the
42 * file places in @size if it's non-NULL. For convenience, the byte
43 * after the end of the content will always be NUL.
46 * static char *read_file_firstline(const char *filename)
50 * all = grab_file(NULL, filename, NULL);
53 * nl = strchr(all, '\n');
59 void *grab_file(const void *ctx, const char *filename, size_t *size);
60 #endif /* CCAN_GRAB_FILE_H */