2 #include <ccan/talloc/talloc.h>
3 #include <ccan/noerr/noerr.h>
9 void *grab_fd(const void *ctx, int fd, size_t *size)
12 size_t max = 16384, s;
19 buffer = talloc_array(ctx, char, max+1);
20 while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
23 buffer = talloc_realloc(ctx, buffer, char, max*=2 + 1);
34 void *grab_file(const void *ctx, const char *filename, size_t *size)
40 fd = dup(STDIN_FILENO);
42 fd = open(filename, O_RDONLY, 0);
47 buffer = grab_fd(ctx, fd, size);