X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FParse.cc;h=5cd4e4c577d28d31a0b92df740b21832985e0a34;hb=8ce5d6817ae748496d7db06ff4b35ad496fa3d21;hp=87235100f46e91ae1ad0b216b5231deaf5344363;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/Parse.cc b/senf/Utils/Console/Parse.cc index 8723510..5cd4e4c 100644 --- a/senf/Utils/Console/Parse.cc +++ b/senf/Utils/Console/Parse.cc @@ -28,11 +28,12 @@ // Custom includes #include +#include #include #include #include -#include "../../Utils/Exception.hh" -#include "../../Utils/senfassert.hh" +#include +#include //#include "Parse.mpp" #define prefix_ @@ -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); }