@matheusbsbs / matheus-bagliano / commits / 896e4bfcec
Fork 0

vcs-svn: make buffer_read_binary API more convenient

buffer_read_binary is a thin wrapper around fread, but its signature is wrong: - fread can fill an arbitrary in-memory buffer. buffer_read_binary is limited to buffers whose size is representable by a 32-bit integer. - The result from fread is the number of bytes actually read. buffer_read_binary only reports the number of bytes read by incrementing sb->len by that amount and returns void. Fix both: let buffer_read_binary accept a size_t instead of uint32_t for the number of bytes to read and as a convenience return the number of bytes actually read. 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>

Jonathan Nieder committed Jan 2, 2011 at 21:37 UTC 896e4bfcec4f6b489aba2197f60a59bc7f45a8ac
2 files changed +4 -4
vcs-svn/line_buffer.c
+3 -3
@@ -91,10 +91,10 @@ char *buffer_read_line(struct line_buffer *buf)
91 return buf->line_buffer;
92 }
93
94 -void buffer_read_binary(struct line_buffer *buf,
95 - struct strbuf *sb, uint32_t size)
94 +size_t buffer_read_binary(struct line_buffer *buf,
95 + struct strbuf *sb, size_t size)
96 {
97 - strbuf_fread(sb, size, buf->infile);
97 + return strbuf_fread(sb, size, buf->infile);
98 }
99
100 off_t buffer_copy_bytes(struct line_buffer *buf, off_t nbytes)
vcs-svn/line_buffer.h
+1 -1
@@ -23,7 +23,7 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
23 int buffer_ferror(struct line_buffer *buf);
24 char *buffer_read_line(struct line_buffer *buf);
25 int buffer_read_char(struct line_buffer *buf);
26 -void buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, uint32_t len);
26 +size_t buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, size_t len);
27 /* Returns number of bytes read (not necessarily written). */
28 off_t buffer_copy_bytes(struct line_buffer *buf, off_t len);
29 off_t buffer_skip_bytes(struct line_buffer *buf, off_t len);