add check on write failed in old TGA screenshot code

This commit is contained in:
Alam Ed Arias 2015-01-10 17:26:29 -05:00
parent 0c106a4ccc
commit f5cd1d5ebc
1 changed files with 10 additions and 2 deletions

View File

@ -726,7 +726,11 @@ static inline boolean saveTGA(const char *file_name, void *buffer,
tga_hdr.image_type = 2;
tga_hdr.image_descriptor = 32;
write(fd, &tga_hdr, sizeof (TGAHeader));
if ( -1 == write(fd, &tga_hdr, sizeof (TGAHeader)))
{
close(fd);
return false;
}
// format to 888 BGR
for (i = 0; i < width * height * 3; i+=3)
{
@ -734,7 +738,11 @@ static inline boolean saveTGA(const char *file_name, void *buffer,
buf8[i] = buf8[i+2];
buf8[i+2] = temp;
}
write(fd, buffer, width * height * 3);
if ( -1 == write(fd, buffer, width * height * 3))
{
close(fd);
return false;
}
close(fd);
return true;
}