TOOLS := tools/ccan_depends tools/doc_extract tools/namespacize tools/modfiles
TOOLS_SRCS := $(filter-out $(TOOLS:%=%.c), $(wildcard tools/*.c))
TOOLS_DEPS := $(TOOLS_SRCS:%.c=%.d) $(TOOLS:%=%.d)
-TOOLS_CCAN_MODULES := asort err foreach hash htable list noerr opt rbuf \
+TOOLS_CCAN_MODULES := asort err foreach hash htable list membuf noerr opt rbuf \
read_write_all str take tal tal/grab_file tal/link tal/path tal/str time
TOOLS_CCAN_SRCS := $(wildcard $(TOOLS_CCAN_MODULES:%=ccan/%/*.c))
TOOLS_OBJS := $(TOOLS_SRCS:%.c=%.o) $(TOOLS_CCAN_SRCS:%.c=%.o)
char *cmd;
FILE *p;
struct rbuf in;
+ char *str;
va_start(ap, format);
cmd = tal_vfmt(ctx, format, ap);
err(1, "Executing '%s'", cmd);
/* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */
- rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0);
- if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
+ rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0, membuf_tal_realloc);
+ str = rbuf_read_str(&in, 0);
+ if (!str)
err(1, "Reading from '%s'", cmd);
pclose(p);
- return tal_strsplit(ctx, in.buf, "\n", STR_EMPTY_OK);
+ return tal_strsplit(ctx, str, "\n", STR_EMPTY_OK);
}
/* Be careful about trying to compile over running programs (parallel make).
struct rbuf in;
int status, ms;
struct timeabs start;
+ const char *ret;
*ok = false;
if (pipe(p) != 0)
}
close(p[1]);
- rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096);
- if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
- in.buf = tal_free(in.buf);
+ rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096, membuf_tal_realloc);
+ ret = rbuf_read_str(&in, '\0');
+ if (!ret)
+ tal_free(rbuf_cleanup(&in));
/* This shouldn't fail... */
if (waitpid(pid, &status, 0) != pid)
*timeout_ms -= ms;
close(p[0]);
if (tools_verbose) {
- printf("%s", in.buf);
+ printf("%s", ret);
printf("Finished: %u ms, %s %u\n", ms,
WIFEXITED(status) ? "exit status" : "killed by signal",
WIFEXITED(status) ? WEXITSTATUS(status)
: WTERMSIG(status));
}
*ok = (WIFEXITED(status) && WEXITSTATUS(status) == 0);
- return in.buf;
+ return ret;
}
/* Tals *output off ctx; return false if command fails. */
return ret;
}
-void *do_tal_realloc(void *p, size_t size)
+void *membuf_tal_realloc(struct membuf *mb, void *p, size_t size)
{
tal_resize((char **)&p, size);
return p;
void keep_temp_dir(void);
bool move_file(const char *oldname, const char *newname);
-void *do_tal_realloc(void *p, size_t size);
+void *membuf_tal_realloc(struct membuf *mb, void *p, size_t size);
/* Freed on exit: a good parent for auto cleanup. */
tal_t *autofree(void);