vcs-svn: allow input errors to be detected promptly
authorJonathan Nieder <jrnieder@gmail.com>
Mon, 11 Oct 2010 02:51:21 +0000 (21:51 -0500)
committerJonathan Nieder <jrnieder@gmail.com>
Mon, 7 Mar 2011 07:32:51 +0000 (01:32 -0600)
The line_buffer library silently flags input errors until
buffer_deinit time; unfortunately, by that point usually errno is
invalid.  Expose the error flag so callers can check for and
report errors early for easy debugging.

some_error_prone_operation(...);
if (buffer_ferror(buf))
return error("input error: %s", strerror(errno));

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>
vcs-svn/line_buffer.c
vcs-svn/line_buffer.h

index aedf105b70586f2ef7567547426bb6622799b067..eb8a6a7f7b67fb56f28f42e39b92736f91b0af85 100644 (file)
@@ -59,6 +59,11 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf)
        return pos;
 }
 
+int buffer_ferror(struct line_buffer *buf)
+{
+       return ferror(buf->infile);
+}
+
 int buffer_read_char(struct line_buffer *buf)
 {
        return fgetc(buf->infile);
index 96ce966a229110e6775cd33ee01a93d5f133404e..3c9629e09d3442acb1216754cdc4721ffba89c1b 100644 (file)
@@ -21,6 +21,7 @@ int buffer_tmpfile_init(struct line_buffer *buf);
 FILE *buffer_tmpfile_rewind(struct line_buffer *buf);  /* prepare to write. */
 long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
 
+int buffer_ferror(struct line_buffer *buf);
 char *buffer_read_line(struct line_buffer *buf);
 char *buffer_read_string(struct line_buffer *buf, uint32_t len);
 int buffer_read_char(struct line_buffer *buf);