ENH: add better error reporting for file open failures

This commit is contained in:
Bill Hoffman 2004-09-07 16:55:25 -04:00
parent 8f92e8c069
commit b5bdf2cb0a
14 changed files with 17 additions and 2 deletions

View File

@ -327,9 +327,10 @@ bool cmCacheManager::SaveCache(const char* path)
tempFile += ".tmp"; tempFile += ".tmp";
std::ofstream fout(tempFile.c_str()); std::ofstream fout(tempFile.c_str());
if(!fout) if(!fout)
{ {
cmSystemTools::Error("Unable to open cache file for save. ", cmSystemTools::Error("Unable to open cache file for save. ",
cacheFile.c_str()); cacheFile.c_str());
cmSystemTools::ReportLastSystemError("");
return false; return false;
} }
// before writting the cache, update the version numbers // before writting the cache, update the version numbers

View File

@ -60,7 +60,8 @@ int DumpHTML(const char* outname)
std::ofstream fout(outname); std::ofstream fout(outname);
if(!fout) if(!fout)
{ {
std::cerr << "failed to open output file: " << outname << "\n"; std::cerr << "failed to open output file: " << outname << "\n";
cmSystemTools::ReportLastSystemError("");
return -1; return -1;
} }
@ -104,6 +105,7 @@ int DumpForCoverage(const char* outname)
if(!fout) if(!fout)
{ {
std::cerr << "failed to open output file: " << outname << "\n"; std::cerr << "failed to open output file: " << outname << "\n";
cmSystemTools::ReportLastSystemError("");
return -1; return -1;
} }
return DumpForCoverageToStream(fout); return DumpForCoverageToStream(fout);

View File

@ -39,6 +39,7 @@ void cmEnableTestingCommand::FinalPass()
if (!fout) if (!fout)
{ {
cmSystemTools::Error("Error Writing ", fname.c_str()); cmSystemTools::Error("Error Writing ", fname.c_str());
cmSystemTools::ReportLastSystemError("");
return; return;
} }

View File

@ -82,6 +82,7 @@ void cmExportLibraryDependenciesCommand::FinalPass()
if (!fout) if (!fout)
{ {
cmSystemTools::Error("Error Writing ", fname.c_str()); cmSystemTools::Error("Error Writing ", fname.c_str());
cmSystemTools::ReportLastSystemError("");
return; return;
} }
cmake* cm = m_Makefile->GetCMakeInstance(); cmake* cm = m_Makefile->GetCMakeInstance();

View File

@ -94,6 +94,7 @@ void cmGlobalCodeWarriorGenerator::OutputProject()
{ {
cmSystemTools::Error("Error can not open project file for write: " cmSystemTools::Error("Error can not open project file for write: "
,fname.c_str()); ,fname.c_str());
cmSystemTools::ReportLastSystemError("");
return; return;
} }
this->WriteProject(fout); this->WriteProject(fout);

View File

@ -364,6 +364,7 @@ void cmGlobalVisualStudio6Generator::OutputDSWFile(cmLocalGenerator* root,
{ {
cmSystemTools::Error("Error can not open DSW file for write: ", cmSystemTools::Error("Error can not open DSW file for write: ",
fname.c_str()); fname.c_str());
cmSystemTools::ReportLastSystemError("");
return; return;
} }
this->WriteDSWFile(fout, root, generators); this->WriteDSWFile(fout, root, generators);

View File

@ -291,6 +291,7 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile(cmLocalGenerator* root,
{ {
cmSystemTools::Error("Error can not open DSW file for write: ", cmSystemTools::Error("Error can not open DSW file for write: ",
fname.c_str()); fname.c_str());
cmSystemTools::ReportLastSystemError("");
return; return;
} }
this->WriteSLNFile(fout.GetStream(), root, generators); this->WriteSLNFile(fout.GetStream(), root, generators);

View File

@ -192,6 +192,7 @@ void cmLocalUnixMakefileGenerator::OutputMakefile(const char* file,
if(!fout) if(!fout)
{ {
cmSystemTools::Error("Error can not open for write: ", file); cmSystemTools::Error("Error can not open for write: ", file);
cmSystemTools::ReportLastSystemError("");
return; return;
} }
fout << "# CMAKE generated Makefile, DO NOT EDIT!\n" fout << "# CMAKE generated Makefile, DO NOT EDIT!\n"

View File

@ -149,6 +149,7 @@ void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, cmTarget
if(!fout) if(!fout)
{ {
cmSystemTools::Error("Error Writing ", fname.c_str()); cmSystemTools::Error("Error Writing ", fname.c_str());
cmSystemTools::ReportLastSystemError("");
} }
this->WriteDSPFile(fout,lname,target); this->WriteDSPFile(fout,lname,target);
fout.close(); fout.close();

View File

@ -2396,6 +2396,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
cmSystemTools::Error( cmSystemTools::Error(
"Could not open file for write in copy operation ", "Could not open file for write in copy operation ",
tempOutputFile.c_str()); tempOutputFile.c_str());
cmSystemTools::ReportLastSystemError("");
return 0; return 0;
} }
std::ifstream fin(sinfile.c_str()); std::ifstream fin(sinfile.c_str());

View File

@ -141,6 +141,7 @@ int cmTryCompileCommand::CoreTryCompileCode(
{ {
cmSystemTools::Error("Failed to create CMakeList file for ", cmSystemTools::Error("Failed to create CMakeList file for ",
outFileName.c_str()); outFileName.c_str());
cmSystemTools::ReportLastSystemError("");
return -1; return -1;
} }

View File

@ -80,6 +80,7 @@ CopyAndFullPathMesaHeader(const char* source,
{ {
cmSystemTools::Error("Could not open file for write in copy operation: ", cmSystemTools::Error("Could not open file for write in copy operation: ",
tempOutputFile.c_str(), outdir); tempOutputFile.c_str(), outdir);
cmSystemTools::ReportLastSystemError("");
return; return;
} }
std::ifstream fin(source); std::ifstream fin(source);

View File

@ -171,6 +171,7 @@ bool cmVTKWrapPythonCommand::WriteInit(const char *kitName,
FILE *fout = fopen(tempOutputFile.c_str(),"w"); FILE *fout = fopen(tempOutputFile.c_str(),"w");
if (!fout) if (!fout)
{ {
cmSystemTools::ReportLastSystemError("cmVTKWrapPythonCommand error:");
return false; return false;
} }

View File

@ -219,6 +219,7 @@ bool cmVTKWrapTclCommand::WriteInit(const char *kitName,
if (!fout) if (!fout)
{ {
cmSystemTools::Error("Failed to open TclInit file for ", tempOutputFile.c_str()); cmSystemTools::Error("Failed to open TclInit file for ", tempOutputFile.c_str());
cmSystemTools::ReportLastSystemError("");
return false; return false;
} }