From c4fba0a358d43fdb2301dd122d68c49dd8471d71 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Wed, 18 Jul 2007 20:31:03 +0200 Subject: Rename read_pipe() with read_fd() and make its buffer nul-terminated. The new name is closer to the purpose of the function. A NUL-terminated buffer makes things easier when callers need that. Since the function returns only the memory written with data, almost always allocating more space than needed because final size is unknown, an extra NUL terminating the buffer is harmless. It is not included in the returned size, so the function remains working as before. Also, now the function allows the buffer passed to be NULL at first, and alloc_nr is now used for growing the buffer, instead size=*2. Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- builtin-stripspace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'builtin-stripspace.c') diff --git a/builtin-stripspace.c b/builtin-stripspace.c index 0c970aa945..55716873dc 100644 --- a/builtin-stripspace.c +++ b/builtin-stripspace.c @@ -79,8 +79,10 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix) size = 1024; buffer = xmalloc(size); - if (read_pipe(0, &buffer, &size)) + if (read_fd(0, &buffer, &size)) { + free(buffer); die("could not read the input"); + } size = stripspace(buffer, size, 0); write_or_die(1, buffer, size); -- cgit v1.2.3