Subject: [boost] [iostreams] mapped_file_source fails for zero sized file
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-02-11 04:00:58
While testing out iostreams memory mapped file source I ran into an
issue where it throws when opening a zero sized file (testing on windows
7 vc11 x64).
for example something like:
namespace io = boost::iostreams;
namespace fs = boost::filesystem;
io::stream<io::mapped_file_source> file( path );
failed create mapping: The volume for a file has been externally altered
so that the opened file is no longer valid.
"When you do not want the size of the file to change (for example, when
mapping read-only files), call CreateFileMapping and specify zero for
both dwMaximumSizeHigh and dwMaximumSizeLow. Doing this creates a file
mapping object that is exactly the same size as the file. Otherwise, you
must calculate or estimate the size of the finished file because file
mapping objects are static in size; once created, their size cannot be
increased or decreased. An attempt to map a file with a length of zero
in this manner fails with an error code of ERROR_FILE_INVALID. Programs
should test for files with a length of zero and reject such files."
I don't see anything in the docs that would lead me to believe this
should throw. Rather I would expect:
std::istream_iterator<char>(file) == std::istream_iterator<char>()