2 #include <ccan/talloc/talloc.h>
3 #include <ccan/noerr/noerr.h>
9 void *grab_fd(const void *ctx, int fd, size_t *size)
20 if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))
25 buffer = talloc_array(ctx, char, max+1);
26 while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
29 buffer = talloc_realloc(ctx, buffer, char, max*2+1);
31 buffer = talloc_realloc(ctx, buffer, char,
49 void *grab_file(const void *ctx, const char *filename, size_t *size)
55 fd = dup(STDIN_FILENO);
57 fd = open(filename, O_RDONLY, 0);
62 buffer = grab_fd(ctx, fd, size);