[libdvdnav-devel] Pointless Checking For Errors On Close
Lawrence D'Oliveiro
ldo at geek-central.gen.nz
Fri Sep 11 09:50:29 CEST 2015
In src/dvd_input.c, dvdinput_close is defined as follows:
int (*dvdinput_close) (dvd_input_t);
This variable is assigned either the file_close routine (defined in the
same file) or, if libdvdcss is available, the css_close routine
exported by that library.
These routines check for an error (negative return) from the close(2)
call, and return the same value if so.
However, such an error check only makes sense (in fact, is mandatory!)
when writing to a file: this is because you need to make sure all
output buffers have been flushed without error, otherwise you could
suffer data loss without realizing it.
But this does not apply when reading from files. And since DVDs are
read-only media, this would apply to all reads from DVDs done by
libdvdnav and libdvdcss.
In libdvdcss, in src/device.c, there is this check for the result from
close(2):
{
int i_ret = close( dvdcss->i_fd );
if( i_ret < 0 )
{
print_error( dvdcss, "Failed to close fd, data loss possible." );
return i_ret;
}
}
That message does not make sense. Data loss is _not_ possible on
closing an input file.
More information about the libdvdnav-devel
mailing list