summaryrefslogtreecommitdiff
path: root/vcs-svn/line_buffer.c
diff options
context:
space:
mode:
authorLibravatar Jonathan Nieder <jrnieder@gmail.com>2010-10-10 21:44:21 -0500
committerLibravatar Jonathan Nieder <jrnieder@gmail.com>2011-03-22 16:39:54 -0500
commitd234f54b2f82067699f36593188e687fc7dc321a (patch)
tree94fe162cfc9d0f44fae444061eadade2c02f5895 /vcs-svn/line_buffer.c
parentvcs-svn: improve support for reading large files (diff)
downloadtgif-d234f54b2f82067699f36593188e687fc7dc321a.tar.xz
vcs-svn: make buffer_skip_bytes return length read
Currently there is no way to detect when input ended if it ended early during buffer_skip_bytes. Tell the calling program how many bytes were actually skipped for easier debugging. Existing callers will still ignore early EOF. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Diffstat (limited to 'vcs-svn/line_buffer.c')
-rw-r--r--vcs-svn/line_buffer.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/vcs-svn/line_buffer.c b/vcs-svn/line_buffer.c
index 747de07e6b..39d52b88b7 100644
--- a/vcs-svn/line_buffer.c
+++ b/vcs-svn/line_buffer.c
@@ -120,15 +120,16 @@ void buffer_copy_bytes(struct line_buffer *buf, off_t len)
}
}
-void buffer_skip_bytes(struct line_buffer *buf, off_t len)
+off_t buffer_skip_bytes(struct line_buffer *buf, off_t nbytes)
{
char byte_buffer[COPY_BUFFER_LEN];
- uint32_t in;
- while (len > 0 && !feof(buf->infile) && !ferror(buf->infile)) {
- in = len < COPY_BUFFER_LEN ? len : COPY_BUFFER_LEN;
- in = fread(byte_buffer, 1, in, buf->infile);
- len -= in;
+ off_t done = 0;
+ while (done < nbytes && !feof(buf->infile) && !ferror(buf->infile)) {
+ off_t len = nbytes - done;
+ size_t in = len < COPY_BUFFER_LEN ? len : COPY_BUFFER_LEN;
+ done += fread(byte_buffer, 1, in, buf->infile);
}
+ return done;
}
void buffer_reset(struct line_buffer *buf)