[PATCH 09/16] vcs-svn: Allow input errors to be detected early
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Oct 11, 2010, 02:51 UTC
- Message-ID
- <20101011025121.GI1553@burratino>
- In-Reply-To
- <20101011023435.GA706@burratino>
Add a buffer_ferror() function to read the error flag from the input stream, so callers can do:
some_error_prone_operation(f, ...);
if (buffer_ferror(f))
return error("input error: %s", strerror(errno));instead of waiting until it is time to close the file.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> --- vcs-svn/line_buffer.c | 5 +++++ vcs-svn/line_buffer.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/vcs-svn/line_buffer.c b/vcs-svn/line_buffer.c index 19caa21..43da509 100644 --- a/vcs-svn/line_buffer.c +++ b/vcs-svn/line_buffer.c @@ -27,6 +27,11 @@ int buffer_deinit(struct line_buffer *buf) return err; } +int buffer_ferror(struct line_buffer *buf) +{ + return ferror(buf->infile); +} + int buffer_at_eof(struct line_buffer *buf) { int ch; diff --git a/vcs-svn/line_buffer.h b/vcs-svn/line_buffer.h index 0269aed..4899289 100644 --- a/vcs-svn/line_buffer.h +++ b/vcs-svn/line_buffer.h @@ -14,6 +14,7 @@ struct line_buffer { int buffer_init(struct line_buffer *buf, const char *filename); int buffer_deinit(struct line_buffer *buf); +int buffer_ferror(struct line_buffer *buf); int buffer_at_eof(struct line_buffer *buf); char *buffer_read_line(struct line_buffer *buf); char *buffer_read_string(struct line_buffer *buf, uint32_t len);
-- 1.7.2.3