1 /* Licensed under LGPLv2+ - see LICENSE file for details */
3 #include <ccan/tal/tal.h>
4 #include <ccan/noerr/noerr.h>
11 void *grab_fd(const void *ctx, int fd)
20 if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))
25 buffer = tal_arr(ctx, char, max+1);
26 while ((ret = read(fd, buffer + size, max - size)) != 0) {
30 return tal_free(buffer);
35 if (extra > 1024 * 1024)
38 if (!tal_resize(&buffer, max+extra+1))
45 tal_resize(&buffer, size+1);
50 void *grab_file(const void *ctx, const char *filename)
56 fd = dup(STDIN_FILENO);
58 fd = open(filename, O_RDONLY, 0);
63 buffer = grab_fd(ctx, fd);