I develop a library that internally uses Boost.IOStreams. Recently, I hit an interesting corner case with file_descriptor_sink
. It looks like doing
file_descriptor_sink s("");
or
file_descriptor_sink s;
s.open("");
is perfectly valid and s.is_open()
definitely returns true
afterwards. For me, this is a complete nonsense. That is to what file is it open?
Two questions in this regard:
Is there any function that I could use to detect this condition? To elaborate, when I first hit this case, I immediately recalled that the following holds:
ofstream ofs(""); assert(!ofs); assert(!ofs.is_open()); assert(ofs.fail());
what is clearly opposite to the
file_descriptor_sink
behavior in terms ofis_open
andfail
is not even available. Otherwise, I'd have to directly test for empty string (pathname) before construction offile_descriptor_sink
in order to track this condition.Do you agree that throwing well-forged exception to a user of the library in this case would be a good idea? I was thinking about
std::system_error
with thebad_file_descriptor
error code.