1 /* Licensed under LGPLv2+ - see LICENSE file for details */
3 #include <ccan/tal/tal.h>
4 #include <ccan/noerr/noerr.h>
10 void *grab_fd(const void *ctx, int fd)
19 if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))
24 buffer = tal_arr(ctx, char, max+1);
25 while ((ret = read(fd, buffer + size, max - size)) > 0) {
29 if (extra > 1024 * 1024)
32 if (!tal_resize(&buffer, max+extra+1))
39 buffer = tal_free(buffer);
42 tal_resize(&buffer, size+1);
48 void *grab_file(const void *ctx, const char *filename)
54 fd = dup(STDIN_FILENO);
56 fd = open(filename, O_RDONLY, 0);
61 buffer = grab_fd(ctx, fd);