summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CMakeVersion.cmake2
-rw-r--r--Source/cmGeneratorExpressionNode.cxx23
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx33
-rw-r--r--Source/cmGlobalNinjaGenerator.h13
-rw-r--r--Source/cmLocalNinjaGenerator.cxx18
-rw-r--r--Source/cmLocalNinjaGenerator.h15
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx4
-rw-r--r--Source/cmNinjaTargetGenerator.cxx4
-rw-r--r--Source/cmNinjaTargetGenerator.h8
-rw-r--r--Source/cmOutputConverter.cxx39
-rw-r--r--Source/cmOutputConverter.h2
-rw-r--r--Source/kwsys/CTestCustom.cmake.in3
-rw-r--r--Source/kwsys/SystemTools.cxx135
13 files changed, 169 insertions, 130 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index ceaf0c7..7f240bc 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,5 +1,5 @@
# CMake version number components.
set(CMake_VERSION_MAJOR 3)
set(CMake_VERSION_MINOR 3)
-set(CMake_VERSION_PATCH 20150927)
+set(CMake_VERSION_PATCH 20150928)
#set(CMake_VERSION_RC 1)
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 31b6766..1c350ab 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -13,6 +13,7 @@
#include "cmGeneratorExpressionNode.h"
#include "cmGlobalGenerator.h"
#include "cmAlgorithms.h"
+#include "cmOutputConverter.h"
//----------------------------------------------------------------------------
std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
@@ -1792,6 +1793,27 @@ static const
TargetFilesystemArtifactNodeGroup<ArtifactPdbTag> targetPdbNodeGroup;
//----------------------------------------------------------------------------
+static const struct ShellPathNode : public cmGeneratorExpressionNode
+{
+ ShellPathNode() {}
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ if (!cmSystemTools::FileIsFullPath(parameters.front()))
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "\"" + parameters.front() + "\" is not an absolute path.");
+ return std::string();
+ }
+ cmOutputConverter converter(context->Makefile->GetStateSnapshot());
+ return converter.ConvertDirectorySeparatorsForShell(parameters.front());
+ }
+} shellPathNode;
+
+//----------------------------------------------------------------------------
const cmGeneratorExpressionNode*
cmGeneratorExpressionNode::GetNode(const std::string &identifier)
{
@@ -1846,6 +1868,7 @@ cmGeneratorExpressionNode::GetNode(const std::string &identifier)
nodeMap["JOIN"] = &joinNode;
nodeMap["LINK_ONLY"] = &linkOnlyNode;
nodeMap["COMPILE_LANGUAGE"] = &languageNode;
+ nodeMap["SHELL_PATH"] = &shellPathNode;
}
NodeMap::const_iterator i = nodeMap.find(identifier);
if (i == nodeMap.end())
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 120bb03..9d8193b 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -818,6 +818,17 @@ void cmGlobalNinjaGenerator::CloseRulesFileStream()
}
}
+std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
+{
+ cmLocalNinjaGenerator *ng =
+ static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
+ std::string convPath = ng->Convert(path, cmOutputConverter::HOME_OUTPUT);
+#ifdef _WIN32
+ cmSystemTools::ReplaceString(convPath, "/", "\\");
+#endif
+ return convPath;
+}
+
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
const std::string &commandLine,
const std::string &sourceFile)
@@ -907,8 +918,6 @@ cmGlobalNinjaGenerator
{
std::string configName =
target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
- cmLocalNinjaGenerator *ng =
- static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
// for frameworks, we want the real name, not smple name
// frameworks always appear versioned, and the build.ninja
@@ -923,13 +932,13 @@ cmGlobalNinjaGenerator
case cmTarget::MODULE_LIBRARY:
{
cmGeneratorTarget *gtgt = this->GetGeneratorTarget(target);
- outputs.push_back(ng->ConvertToNinjaPath(
+ outputs.push_back(this->ConvertToNinjaPath(
gtgt->GetFullPath(configName, false, realname)));
break;
}
case cmTarget::OBJECT_LIBRARY:
case cmTarget::UTILITY: {
- std::string path = ng->ConvertToNinjaPath(
+ std::string path = this->ConvertToNinjaPath(
target->GetMakefile()->GetCurrentBinaryDirectory());
if (path.empty() || path == ".")
outputs.push_back(target->GetName());
@@ -1041,8 +1050,6 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
//get the list of files that cmake itself has generated as a
//product of configuration.
- cmLocalNinjaGenerator *ng =
- static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
for (std::vector<cmLocalGenerator *>::const_iterator i =
this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
@@ -1054,7 +1061,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
typedef std::vector<std::string>::const_iterator vect_it;
for(vect_it j = files.begin(); j != files.end(); ++j)
{
- knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
+ knownDependencies.insert( this->ConvertToNinjaPath( *j ) );
}
//get list files which are implicit dependencies as well and will be phony
//for rebuild manifest
@@ -1062,7 +1069,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
typedef std::vector<std::string>::const_iterator vect_it;
for(vect_it j = lf.begin(); j != lf.end(); ++j)
{
- knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
+ knownDependencies.insert( this->ConvertToNinjaPath( *j ) );
}
std::vector<cmGeneratorExpressionEvaluationFile*> const& ef =
(*i)->GetMakefile()->GetEvaluationFiles();
@@ -1074,7 +1081,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
std::vector<std::string> evaluationFiles = (*li)->GetFiles();
for(vect_it j = evaluationFiles.begin(); j != evaluationFiles.end(); ++j)
{
- knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
+ knownDependencies.insert( this->ConvertToNinjaPath( *j ) );
}
}
}
@@ -1084,7 +1091,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
i != this->TargetAliases.end();
++i)
{
- knownDependencies.insert( ng->ConvertToNinjaPath(i->first) );
+ knownDependencies.insert( this->ConvertToNinjaPath(i->first) );
}
//remove all source files we know will exist.
@@ -1093,7 +1100,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
i != this->AssumedSourceDependencies.end();
++i)
{
- knownDependencies.insert( ng->ConvertToNinjaPath(i->first) );
+ knownDependencies.insert( this->ConvertToNinjaPath(i->first) );
}
//now we difference with CombinedCustomCommandExplicitDependencies to find
@@ -1214,8 +1221,6 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
/*restat=*/ "",
/*generator=*/ true);
- cmLocalNinjaGenerator *ng = static_cast<cmLocalNinjaGenerator *>(lg);
-
cmNinjaDeps implicitDeps;
for(std::vector<cmLocalGenerator*>::const_iterator i =
this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
@@ -1224,7 +1229,7 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
for(std::vector<std::string>::const_iterator fi = lf.begin();
fi != lf.end(); ++fi)
{
- implicitDeps.push_back(ng->ConvertToNinjaPath(*fi));
+ implicitDeps.push_back(this->ConvertToNinjaPath(*fi));
}
}
implicitDeps.push_back("CMakeCache.txt");
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index d204a50..292f7c7 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -220,6 +220,19 @@ public:
cmGeneratedFileStream* GetRulesFileStream() const {
return this->RulesFileStream; }
+ std::string ConvertToNinjaPath(const std::string& path);
+
+ struct MapToNinjaPathImpl {
+ cmGlobalNinjaGenerator* GG;
+ MapToNinjaPathImpl(cmGlobalNinjaGenerator* gg): GG(gg) {}
+ std::string operator()(std::string const& path) {
+ return this->GG->ConvertToNinjaPath(path);
+ }
+ };
+ MapToNinjaPathImpl MapToNinjaPath() {
+ return MapToNinjaPathImpl(this);
+ }
+
void AddCXXCompileCommand(const std::string &commandLine,
const std::string &sourceFile);
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 7525bf2..c46adc1 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -284,15 +284,6 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
os << std::endl;
}
-std::string cmLocalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
-{
- std::string convPath = this->Convert(path, cmLocalGenerator::HOME_OUTPUT);
-#ifdef _WIN32
- cmSystemTools::ReplaceString(convPath, "/", "\\");
-#endif
- return convPath;
-}
-
void
cmLocalNinjaGenerator
::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs)
@@ -316,7 +307,8 @@ void cmLocalNinjaGenerator::AppendCustomCommandDeps(
i != deps.end(); ++i) {
std::string dep;
if (this->GetRealDependency(*i, this->GetConfigName(), dep))
- ninjaDeps.push_back(ConvertToNinjaPath(dep));
+ ninjaDeps.push_back(
+ this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep));
}
}
@@ -413,9 +405,11 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
at us. How to know which ExternalProject step actually provides it?
#endif
std::transform(outputs.begin(), outputs.end(),
- ninjaOutputs.begin(), MapToNinjaPath());
+ ninjaOutputs.begin(),
+ this->GetGlobalNinjaGenerator()->MapToNinjaPath());
std::transform(byproducts.begin(), byproducts.end(),
- ninjaOutputs.begin() + outputs.size(), MapToNinjaPath());
+ ninjaOutputs.begin() + outputs.size(),
+ this->GetGlobalNinjaGenerator()->MapToNinjaPath());
this->AppendCustomCommandDeps(ccg, ninjaDeps);
for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end();
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
index 8d3d49c..1645a8d 100644
--- a/Source/cmLocalNinjaGenerator.h
+++ b/Source/cmLocalNinjaGenerator.h
@@ -50,21 +50,6 @@ public:
std::string GetHomeRelativeOutputPath() const
{ return this->HomeRelativeOutputPath; }
- std::string ConvertToNinjaPath(const std::string& path);
-
- struct map_to_ninja_path {
- cmLocalNinjaGenerator *LocalGenerator;
- map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
- : LocalGenerator(LocalGen) {}
- std::string operator()(const std::string &path) {
- return LocalGenerator->ConvertToNinjaPath(path);
- }
- };
-
- map_to_ninja_path MapToNinjaPath() {
- return map_to_ninja_path(this);
- }
-
void ExpandRuleVariables(std::string& string,
const RuleVariables& replaceValues) {
cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 6d96af5..84c19a3 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -583,7 +583,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
const std::string objPath = GetTarget()->GetSupportDirectory();
- vars["OBJECT_DIR"] = ConvertToNinjaPath(objPath);
+ vars["OBJECT_DIR"] =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->ConvertToNinjaPath(objPath), cmLocalGenerator::SHELL);
EnsureDirectoryExists(objPath);
if (this->GetGlobalGenerator()->IsGCCOnWindows())
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index f46c5b9..6e6dc60 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -771,14 +771,14 @@ cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
// Get the input file location.
std::string input = source.GetFullPath();
input =
- this->Generator->GetLocalGenerator()->ConvertToNinjaPath(input);
+ this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(input);
// Get the output file location.
std::string output = macdir;
output += "/";
output += cmSystemTools::GetFilenameName(input);
output =
- this->Generator->GetLocalGenerator()->ConvertToNinjaPath(output);
+ this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(output);
// Write a build statement to copy the content into the bundle.
this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index a10ceba..0267f63 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -17,11 +17,11 @@
#include "cmStandardIncludes.h"
#include "cmNinjaTypes.h"
+#include "cmGlobalNinjaGenerator.h"
#include "cmLocalNinjaGenerator.h"
#include "cmOSXBundleGenerator.h"
class cmTarget;
-class cmGlobalNinjaGenerator;
class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmMakefile;
@@ -87,10 +87,10 @@ protected:
const std::string& language);
std::string ConvertToNinjaPath(const std::string& path) const {
- return this->GetLocalGenerator()->ConvertToNinjaPath(path);
+ return this->GetGlobalGenerator()->ConvertToNinjaPath(path);
}
- cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
- return this->GetLocalGenerator()->MapToNinjaPath();
+ cmGlobalNinjaGenerator::MapToNinjaPathImpl MapToNinjaPath() const {
+ return this->GetGlobalGenerator()->MapToNinjaPath();
}
/// @return the list of link dependency for the given target @a target.
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index 7be5b3f..5acae2f 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -142,21 +142,7 @@ std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source,
}
else if(output == SHELL || output == WATCOMQUOTE)
{
- // For the MSYS shell convert drive letters to posix paths, so
- // that c:/some/path becomes /c/some/path. This is needed to
- // avoid problems with the shell path translation.
- if(this->GetState()->UseMSYSShell() && !this->LinkScriptShell)
- {
- if(result.size() > 2 && result[1] == ':')
- {
- result[1] = result[0];
- result[0] = '/';
- }
- }
- if(this->GetState()->UseWindowsShell())
- {
- std::replace(result.begin(), result.end(), '/', '\\');
- }
+ result = this->ConvertDirectorySeparatorsForShell(source);
result = this->EscapeForShell(result, true, false, output == WATCOMQUOTE);
}
else if(output == RESPONSE)
@@ -167,6 +153,29 @@ std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source,
}
//----------------------------------------------------------------------------
+std::string cmOutputConverter::ConvertDirectorySeparatorsForShell(
+ const std::string& source) const
+{
+ std::string result = source;
+ // For the MSYS shell convert drive letters to posix paths, so
+ // that c:/some/path becomes /c/some/path. This is needed to
+ // avoid problems with the shell path translation.
+ if(this->GetState()->UseMSYSShell() && !this->LinkScriptShell)
+ {
+ if(result.size() > 2 && result[1] == ':')
+ {
+ result[1] = result[0];
+ result[0] = '/';
+ }
+ }
+ if(this->GetState()->UseWindowsShell())
+ {
+ std::replace(result.begin(), result.end(), '/', '\\');
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
std::string cmOutputConverter::Convert(RelativeRoot remote,
const std::string& local,
OutputFormat output,
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index ed7739e..852df5d 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -45,6 +45,8 @@ public:
std::string Convert(RelativeRoot remote, const std::string& local,
OutputFormat output = UNCHANGED,
bool optional = false) const;
+ std::string ConvertDirectorySeparatorsForShell(
+ const std::string& source) const;
/**
* Get path for the specified relative root.
diff --git a/Source/kwsys/CTestCustom.cmake.in b/Source/kwsys/CTestCustom.cmake.in
index d6f802e..760221b 100644
--- a/Source/kwsys/CTestCustom.cmake.in
+++ b/Source/kwsys/CTestCustom.cmake.in
@@ -9,7 +9,6 @@
# resulting memory leaks are not logged by valgrind anyway. Therefore, we
# don't have to exclude it.
-set(CTEST_CUSTOM_MEMCHECK_IGNORE
- ${CTEST_CUSTOM_MEMCHECK_IGNORE}
+list(APPEND CTEST_CUSTOM_MEMCHECK_IGNORE
kwsys.testProcess-10
)
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 3857e41..80289b8 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -2365,95 +2365,102 @@ bool SystemTools::CopyFileAlways(const std::string& source, const std::string& d
}
mode_t perm = 0;
bool perms = SystemTools::GetPermissions(source, perm);
-
- const int bufferSize = 4096;
- char buffer[bufferSize];
-
- // If destination is a directory, try to create a file with the same
- // name as the source in that directory.
-
std::string real_destination = destination;
- std::string destination_dir;
- if(SystemTools::FileExists(destination) &&
- SystemTools::FileIsDirectory(destination))
+
+ if(SystemTools::FileIsDirectory(source))
{
- destination_dir = real_destination;
- SystemTools::ConvertToUnixSlashes(real_destination);
- real_destination += '/';
- std::string source_name = source;
- real_destination += SystemTools::GetFilenameName(source_name);
+ SystemTools::MakeDirectory(destination);
}
else
{
- destination_dir = SystemTools::GetFilenamePath(destination);
- }
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+
+ // If destination is a directory, try to create a file with the same
+ // name as the source in that directory.
+
+ std::string destination_dir;
+ if(SystemTools::FileExists(destination) &&
+ SystemTools::FileIsDirectory(destination))
+ {
+ destination_dir = real_destination;
+ SystemTools::ConvertToUnixSlashes(real_destination);
+ real_destination += '/';
+ std::string source_name = source;
+ real_destination += SystemTools::GetFilenameName(source_name);
+ }
+ else
+ {
+ destination_dir = SystemTools::GetFilenamePath(destination);
+ }
- // Create destination directory
+ // Create destination directory
- SystemTools::MakeDirectory(destination_dir);
+ SystemTools::MakeDirectory(destination_dir);
- // Open files
+ // Open files
#if defined(_WIN32)
- kwsys::ifstream fin(Encoding::ToNarrow(
- SystemTools::ConvertToWindowsExtendedPath(source)).c_str(),
- std::ios::in | std::ios::binary);
+ kwsys::ifstream fin(Encoding::ToNarrow(
+ SystemTools::ConvertToWindowsExtendedPath(source)).c_str(),
+ std::ios::in | std::ios::binary);
#else
- kwsys::ifstream fin(source.c_str(),
- std::ios::in | std::ios::binary);
+ kwsys::ifstream fin(source.c_str(),
+ std::ios::in | std::ios::binary);
#endif
- if(!fin)
- {
- return false;
- }
+ if(!fin)
+ {
+ return false;
+ }
- // try and remove the destination file so that read only destination files
- // can be written to.
- // If the remove fails continue so that files in read only directories
- // that do not allow file removal can be modified.
- SystemTools::RemoveFile(real_destination);
+ // try and remove the destination file so that read only destination files
+ // can be written to.
+ // If the remove fails continue so that files in read only directories
+ // that do not allow file removal can be modified.
+ SystemTools::RemoveFile(real_destination);
#if defined(_WIN32)
- kwsys::ofstream fout(Encoding::ToNarrow(
- SystemTools::ConvertToWindowsExtendedPath(real_destination)).c_str(),
+ kwsys::ofstream fout(Encoding::ToNarrow(
+ SystemTools::ConvertToWindowsExtendedPath(real_destination)).c_str(),
std::ios::out | std::ios::trunc | std::ios::binary);
#else
- kwsys::ofstream fout(real_destination.c_str(),
+ kwsys::ofstream fout(real_destination.c_str(),
std::ios::out | std::ios::trunc | std::ios::binary);
#endif
- if(!fout)
- {
- return false;
- }
-
- // This copy loop is very sensitive on certain platforms with
- // slightly broken stream libraries (like HPUX). Normally, it is
- // incorrect to not check the error condition on the fin.read()
- // before using the data, but the fin.gcount() will be zero if an
- // error occurred. Therefore, the loop should be safe everywhere.
- while(fin)
- {
- fin.read(buffer, bufferSize);
- if(fin.gcount())
+ if(!fout)
{
- fout.write(buffer, fin.gcount());
+ return false;
}
- else
+
+ // This copy loop is very sensitive on certain platforms with
+ // slightly broken stream libraries (like HPUX). Normally, it is
+ // incorrect to not check the error condition on the fin.read()
+ // before using the data, but the fin.gcount() will be zero if an
+ // error occurred. Therefore, the loop should be safe everywhere.
+ while(fin)
{
- break;
+ fin.read(buffer, bufferSize);
+ if(fin.gcount())
+ {
+ fout.write(buffer, fin.gcount());
+ }
+ else
+ {
+ break;
+ }
}
- }
- // Make sure the operating system has finished writing the file
- // before closing it. This will ensure the file is finished before
- // the check below.
- fout.flush();
+ // Make sure the operating system has finished writing the file
+ // before closing it. This will ensure the file is finished before
+ // the check below.
+ fout.flush();
- fin.close();
- fout.close();
+ fin.close();
+ fout.close();
- if(!fout)
- {
- return false;
+ if(!fout)
+ {
+ return false;
+ }
}
if ( perms )
{