summaryrefslogtreecommitdiff
path: root/vcs-svn/line_buffer.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-01-03 03:05:46 (GMT)
committerJonathan Nieder <jrnieder@gmail.com>2011-02-26 10:59:37 (GMT)
commite832f43c1d26bf70611d98b62d95870a99292add (patch)
tree1b24a34f03268e1061ce6ee9c679c05b9912724b /vcs-svn/line_buffer.c
parentd280f68313eecb8b3838c70641a246382d5e5343 (diff)
downloadgit-e832f43c1d26bf70611d98b62d95870a99292add.zip
git-e832f43c1d26bf70611d98b62d95870a99292add.tar.gz
git-e832f43c1d26bf70611d98b62d95870a99292add.tar.bz2
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 <jrnieder@gmail.com>
Diffstat (limited to 'vcs-svn/line_buffer.c')
-rw-r--r--vcs-svn/line_buffer.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/vcs-svn/line_buffer.c b/vcs-svn/line_buffer.c
index 806932b..661b007 100644
--- a/vcs-svn/line_buffer.c
+++ b/vcs-svn/line_buffer.c
@@ -56,6 +56,12 @@ char *buffer_read_string(struct line_buffer *buf, uint32_t len)
return ferror(buf->infile) ? NULL : buf->blob_buffer.buf;
}
+void buffer_read_binary(struct line_buffer *buf,
+ struct strbuf *sb, uint32_t size)
+{
+ strbuf_fread(sb, size, buf->infile);
+}
+
void buffer_copy_bytes(struct line_buffer *buf, uint32_t len)
{
char byte_buffer[COPY_BUFFER_LEN];