@matheusbsbs / matheus-bagliano / commits / efc749b48f
Fork 0

vcs-svn: allow input errors to be detected promptly

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>

Jonathan Nieder committed Oct 10, 2010 at 21:51 UTC efc749b48f729992d838484d652ba24f5291ee28
2 files changed +6
vcs-svn/line_buffer.c
+5
@@ -59,6 +59,11 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf)
59 return pos;
60 }
61
62 +int buffer_ferror(struct line_buffer *buf)
63 +{
64 + return ferror(buf->infile);
65 +}
66 +
67 int buffer_read_char(struct line_buffer *buf)
68 {
69 return fgetc(buf->infile);
vcs-svn/line_buffer.h
+1
@@ -21,6 +21,7 @@ int buffer_tmpfile_init(struct line_buffer *buf);
21 FILE *buffer_tmpfile_rewind(struct line_buffer *buf); /* prepare to write. */
22 long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
23
24 +int buffer_ferror(struct line_buffer *buf);
25 char *buffer_read_line(struct line_buffer *buf);
26 char *buffer_read_string(struct line_buffer *buf, uint32_t len);
27 int buffer_read_char(struct line_buffer *buf);