X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FParse.cc;h=5cd4e4c577d28d31a0b92df740b21832985e0a34;hb=941ca33da6ee01d78c07fa6b514de10da1ef3948;hp=40a61fc34ffb5395ebb5075b997cfa9231573d2e;hpb=26610f603ebdd465307b9621f532c1fe19fd5571;p=senf.git diff --git a/senf/Utils/Console/Parse.cc b/senf/Utils/Console/Parse.cc index 40a61fc..5cd4e4c 100644 --- a/senf/Utils/Console/Parse.cc +++ b/senf/Utils/Console/Parse.cc @@ -28,6 +28,7 @@ // Custom includes #include +#include #include #include #include @@ -368,8 +369,21 @@ prefix_ void senf::console::CommandParser::parse(std::string const & command, Ca prefix_ void senf::console::CommandParser::parseFile(std::string const & filename, Callback cb) { + // file_iterator sets errno to EINVAL and returns error when file size is 0 + // so we check the file size before + struct stat statBuf; + if (stat( filename.c_str(), &statBuf) != 0) + throw SystemException(errno SENF_EXC_DEBUGINFO); + if (statBuf.st_size == 0) return; boost::spirit::file_iterator<> i (filename); - if (!i) throw SystemException(ENOENT SENF_EXC_DEBUGINFO); + if (!i) { + if (errno == 0) + // hmm.. errno==0 but the file_iterator is false; something is wrong but we + // do not know what exactly, so we throw a SystemeException with EINVAL + throw SystemException(EINVAL SENF_EXC_DEBUGINFO); + else + throw SystemException(errno SENF_EXC_DEBUGINFO); + } boost::spirit::file_iterator<> const i_end (i.make_end()); parseLoop(i, i_end, filename, cb); }