close infile on error condition. Make failure to read not be fatal.
This commit is contained in:
parent
7278448b01
commit
599848346e
|
@ -746,37 +746,35 @@ Image *Image::HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p
|
||||||
return( high_image );
|
return( high_image );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::ReadRaw( const char *filename )
|
bool Image::ReadRaw( const char *filename ) {
|
||||||
{
|
|
||||||
FILE *infile;
|
FILE *infile;
|
||||||
if ( (infile = fopen( filename, "rb" )) == NULL )
|
if ( (infile = fopen( filename, "rb" )) == NULL ) {
|
||||||
{
|
Error("Can't open %s: %s", filename, strerror(errno));
|
||||||
Error( "Can't open %s: %s", filename, strerror(errno) );
|
return false;
|
||||||
return( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if ( fstat( fileno(infile), &statbuf ) < 0 )
|
if ( fstat( fileno(infile), &statbuf ) < 0 ) {
|
||||||
{
|
fclose(infile);
|
||||||
Error( "Can't fstat %s: %s", filename, strerror(errno) );
|
Error("Can't fstat %s: %s", filename, strerror(errno));
|
||||||
return( false );
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( statbuf.st_size != size )
|
if ( statbuf.st_size != size ) {
|
||||||
{
|
fclose(infile);
|
||||||
Error( "Raw file size mismatch, expected %d bytes, found %ld", size, statbuf.st_size );
|
Error("Raw file size mismatch, expected %d bytes, found %ld", size, statbuf.st_size);
|
||||||
return( false );
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fread( buffer, size, 1, infile ) < 1 )
|
if ( fread(buffer, size, 1, infile) < 1 ) {
|
||||||
{
|
fclose(infile);
|
||||||
Fatal( "Unable to read from '%s': %s", filename, strerror(errno) );
|
Error("Unable to read from '%s': %s", filename, strerror(errno));
|
||||||
return( false );
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( infile );
|
fclose( infile );
|
||||||
|
|
||||||
return( true );
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::WriteRaw( const char *filename ) const {
|
bool Image::WriteRaw( const char *filename ) const {
|
||||||
|
|
Loading…
Reference in New Issue