From e832f43c1d26bf70611d98b62d95870a99292add Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 2 Jan 2011 21:05:46 -0600 Subject: vcs-svn: add binary-safe read function buffer_read_string works well for non line-oriented input except for one problem: it does not tell the caller how many bytes were actually written. This means that unless one is very careful about checking for errors (and eof) the calling program cannot tell the difference between the string "foo" followed by an early end of file and the string "foo\0bar\0baz". So introduce a variant that reports the length, too, a thinner wrapper around strbuf_fread. Its result is written to a strbuf so the caller does not need to keep track of the number of bytes read. Signed-off-by: Jonathan Nieder --- test-line-buffer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test-line-buffer.c') diff --git a/test-line-buffer.c b/test-line-buffer.c index ec19b13ee2..19bf2d4403 100644 --- a/test-line-buffer.c +++ b/test-line-buffer.c @@ -3,6 +3,7 @@ */ #include "git-compat-util.h" +#include "strbuf.h" #include "vcs-svn/line_buffer.h" static uint32_t strtouint32(const char *s) @@ -17,6 +18,15 @@ static uint32_t strtouint32(const char *s) static void handle_command(const char *command, const char *arg, struct line_buffer *buf) { switch (*command) { + case 'b': + if (!prefixcmp(command, "binary ")) { + struct strbuf sb = STRBUF_INIT; + strbuf_addch(&sb, '>'); + buffer_read_binary(buf, &sb, strtouint32(arg)); + fwrite(sb.buf, 1, sb.len, stdout); + strbuf_release(&sb); + return; + } case 'c': if (!prefixcmp(command, "copy ")) { buffer_copy_bytes(buf, strtouint32(arg)); -- cgit v1.2.1