apps: ppm_writer: Return EIO on I/O errors

EINVAL should be returned only when the requested format is unsupported.
On errors when writing the data, let's return EIO, which is the closest
description of the situation when we don't inspect it more.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Milan Zamazal 2025-01-24 22:58:03 +01:00 committed by Laurent Pinchart
parent 8072518ca9
commit 8aef7b4dfb

View file

@ -29,7 +29,7 @@ int PPMWriter::write(const char *filename,
std::ofstream output(filename, std::ios::binary);
if (!output) {
std::cerr << "Failed to open ppm file: " << filename << std::endl;
return -EINVAL;
return -EIO;
}
output << "P6" << std::endl
@ -37,7 +37,7 @@ int PPMWriter::write(const char *filename,
<< "255" << std::endl;
if (!output) {
std::cerr << "Failed to write the file header" << std::endl;
return -EINVAL;
return -EIO;
}
const unsigned int rowLength = config.size.width * 3;
@ -46,7 +46,7 @@ int PPMWriter::write(const char *filename,
output.write(row, rowLength);
if (!output) {
std::cerr << "Failed to write image data at row " << y << std::endl;
return -EINVAL;
return -EIO;
}
}