Commit e4142e58 authored by Rusty Russell's avatar Rusty Russell

rbuf, tools: clean up rbuf usage.

We should use rbuf primitives not reach inside to membuf.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent b3cc8ae7
......@@ -54,7 +54,7 @@ int main(void)
}
rbuf_consume(&in, sizeof(buf));
}
free(membuf_cleanup(&in.m));
free(rbuf_cleanup(&in));
/* This exits depending on whether all tests passed */
return exit_status();
......
......@@ -60,7 +60,7 @@ int main(void)
p = rbuf_read_str(&in, '\n');
ok1(errno == 0);
ok1(p == NULL);
free(membuf_cleanup(&in.m));
free(rbuf_cleanup(&in));
/* This exits depending on whether all tests passed */
return exit_status();
......
......@@ -20,7 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...)
char *cmd;
FILE *p;
struct rbuf in;
char *str;
char *ret;
va_start(ap, format);
cmd = tal_vfmt(ctx, format, ap);
......@@ -31,13 +31,14 @@ lines_from_cmd(const void *ctx, const char *format, ...)
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, membuf_tal_realloc);
str = rbuf_read_str(&in, 0);
if (!str)
rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0,
tal_rbuf_enlarge);
ret = rbuf_read_str(&in, 0);
if (!ret && errno)
err(1, "Reading from '%s'", cmd);
pclose(p);
return tal_strsplit(ctx, str, "\n", STR_EMPTY_OK);
return tal_strsplit(ctx, ret, "\n", STR_EMPTY_OK);
}
/* Be careful about trying to compile over running programs (parallel make).
......
......@@ -40,7 +40,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
struct rbuf in;
int status, ms;
struct timeabs start;
const char *ret;
char *ret;
*ok = false;
if (pipe(p) != 0)
......@@ -83,10 +83,8 @@ char *run_with_timeout(const void *ctx, const char *cmd,
}
close(p[1]);
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));
rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096, tal_rbuf_enlarge);
ret = rbuf_read_str(&in, 0);
/* This shouldn't fail... */
if (waitpid(pid, &status, 0) != pid)
......@@ -269,7 +267,7 @@ free:
return ret;
}
void *membuf_tal_realloc(struct membuf *mb, void *p, size_t size)
void *tal_rbuf_enlarge(struct membuf *mb, void *p, size_t size)
{
tal_resize((char **)&p, size);
return p;
......
......@@ -67,7 +67,7 @@ const char *temp_dir(void);
void keep_temp_dir(void);
bool move_file(const char *oldname, const char *newname);
void *membuf_tal_realloc(struct membuf *mb, void *p, size_t size);
void *tal_rbuf_enlarge(struct membuf *mb, void *p, size_t len);
/* Freed on exit: a good parent for auto cleanup. */
tal_t *autofree(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment