icemulti: Add missing error checks

This commit is contained in:
Roland Lutz 2017-07-10 14:03:56 +02:00
parent 450306dfb1
commit e9e49bb5db
1 changed files with 11 additions and 2 deletions

View File

@ -87,19 +87,28 @@ class Image {
uint32_t offs;
public:
Image(const char *filename) : filename(filename), ifs(filename, std::ifstream::binary) {}
Image(const char *filename);
size_t size();
void write(std::ostream &ofs, uint32_t &file_offset);
void place(uint32_t o) { offs = o; }
uint32_t offset() const { return offs; }
};
Image::Image(const char *filename) : filename(filename), ifs(filename, std::ifstream::binary)
{
if (ifs.fail())
error("can't open input image `%s': %s\n", filename, strerror(errno));
}
size_t Image::size()
{
ifs.seekg (0, ifs.end);
if (ifs.fail())
error("can't seek on input image `%s': %s\n", filename, strerror(errno));
size_t length = ifs.tellg();
ifs.seekg (0, ifs.beg);
if (ifs.fail())
error("can't seek on input image `%s': %s\n", filename, strerror(errno));
return length;
}