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) ...@@ -54,7 +54,7 @@ int main(void)
} }
rbuf_consume(&in, sizeof(buf)); rbuf_consume(&in, sizeof(buf));
} }
free(membuf_cleanup(&in.m)); free(rbuf_cleanup(&in));
/* This exits depending on whether all tests passed */ /* This exits depending on whether all tests passed */
return exit_status(); return exit_status();
......
...@@ -60,7 +60,7 @@ int main(void) ...@@ -60,7 +60,7 @@ int main(void)
p = rbuf_read_str(&in, '\n'); p = rbuf_read_str(&in, '\n');
ok1(errno == 0); ok1(errno == 0);
ok1(p == NULL); ok1(p == NULL);
free(membuf_cleanup(&in.m)); free(rbuf_cleanup(&in));
/* This exits depending on whether all tests passed */ /* This exits depending on whether all tests passed */
return exit_status(); return exit_status();
......
...@@ -20,7 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...) ...@@ -20,7 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...)
char *cmd; char *cmd;
FILE *p; FILE *p;
struct rbuf in; struct rbuf in;
char *str; char *ret;
va_start(ap, format); va_start(ap, format);
cmd = tal_vfmt(ctx, format, ap); cmd = tal_vfmt(ctx, format, ap);
...@@ -31,13 +31,14 @@ lines_from_cmd(const void *ctx, const char *format, ...) ...@@ -31,13 +31,14 @@ lines_from_cmd(const void *ctx, const char *format, ...)
err(1, "Executing '%s'", cmd); err(1, "Executing '%s'", cmd);
/* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */ /* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */
rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0, membuf_tal_realloc); rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0,
str = rbuf_read_str(&in, 0); tal_rbuf_enlarge);
if (!str) ret = rbuf_read_str(&in, 0);
if (!ret && errno)
err(1, "Reading from '%s'", cmd); err(1, "Reading from '%s'", cmd);
pclose(p); 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). /* 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, ...@@ -40,7 +40,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
struct rbuf in; struct rbuf in;
int status, ms; int status, ms;
struct timeabs start; struct timeabs start;
const char *ret; char *ret;
*ok = false; *ok = false;
if (pipe(p) != 0) if (pipe(p) != 0)
...@@ -83,10 +83,8 @@ char *run_with_timeout(const void *ctx, const char *cmd, ...@@ -83,10 +83,8 @@ char *run_with_timeout(const void *ctx, const char *cmd,
} }
close(p[1]); close(p[1]);
rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096, membuf_tal_realloc); rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096, tal_rbuf_enlarge);
ret = rbuf_read_str(&in, '\0'); ret = rbuf_read_str(&in, 0);
if (!ret)
tal_free(rbuf_cleanup(&in));
/* This shouldn't fail... */ /* This shouldn't fail... */
if (waitpid(pid, &status, 0) != pid) if (waitpid(pid, &status, 0) != pid)
...@@ -269,7 +267,7 @@ free: ...@@ -269,7 +267,7 @@ free:
return ret; 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); tal_resize((char **)&p, size);
return p; return p;
......
...@@ -67,7 +67,7 @@ const char *temp_dir(void); ...@@ -67,7 +67,7 @@ const char *temp_dir(void);
void keep_temp_dir(void); void keep_temp_dir(void);
bool move_file(const char *oldname, const char *newname); 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. */ /* Freed on exit: a good parent for auto cleanup. */
tal_t *autofree(void); 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