diff options
author | Thomas White <taw@physics.org> | 2011-03-28 18:47:13 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:22 +0100 |
commit | 176b63b62ec8e9ee1cc782d25399f3abf25c85f2 (patch) | |
tree | 5f7616652715a3f33dd926934d432d5b8c219d96 /src/stream.c | |
parent | 2a6ce4a23bd88ca2603b47559ac831dbead6c6ad (diff) |
Fix up stream error handling
Diffstat (limited to 'src/stream.c')
-rw-r--r-- | src/stream.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/stream.c b/src/stream.c index fd4f5c47..289d274e 100644 --- a/src/stream.c +++ b/src/stream.c @@ -129,6 +129,11 @@ int count_patterns(FILE *fh) } while ( rval != NULL ); + if ( ferror(fh) ) { + ERROR("Read error while counting patterns.\n"); + return 0; + } + return n_total_patterns; } @@ -319,7 +324,7 @@ int read_chunk(FILE *fh, struct image *image) rval = fgets(line, 1023, fh); /* Trouble? */ - if ( rval == NULL ) return 1; + if ( rval == NULL ) break; chomp(line); @@ -378,12 +383,16 @@ int read_chunk(FILE *fh, struct image *image) } } - } while ( strcmp(line, CHUNK_END_MARKER) != 0 ); + if ( strcmp(line, CHUNK_END_MARKER) == 0 ) { + if ( have_filename && have_ev ) return 0; + ERROR("Incomplete chunk found in input file.\n"); + return 1; + } - if ( have_filename && have_ev ) return 0; + } while ( 1 ); - ERROR("Incomplete chunk found in input file.\n"); - return 1; + return 1; /* Either error or EOF, don't care because we will complain + * on the terminal if it was an error. */ } |