diff --git a/OMCompiler/Compiler/Util/System.mo b/OMCompiler/Compiler/Util/System.mo index 94bb585091e..2b9c19d00f1 100644 --- a/OMCompiler/Compiler/Util/System.mo +++ b/OMCompiler/Compiler/Util/System.mo @@ -1119,7 +1119,7 @@ public function fileContentsEqual external "C" result = SystemImpl__fileContentsEqual(file1,file2) annotation(Library = {"omcruntime"}); end fileContentsEqual; -public function rename +public function rename "returns true if success, false otherwise" input String source; input String dest; output Boolean result; diff --git a/OMCompiler/Compiler/runtime/systemimpl.c b/OMCompiler/Compiler/runtime/systemimpl.c index 1cc6e031a68..0f7118aae7e 100644 --- a/OMCompiler/Compiler/runtime/systemimpl.c +++ b/OMCompiler/Compiler/runtime/systemimpl.c @@ -2995,7 +2995,7 @@ int SystemImpl__fileContentsEqual(const char *file1, const char *file2) int SystemImpl__rename(const char *source, const char *dest) { - return omc_rename(source, dest); + return (0 == omc_rename(source, dest)); } char* SystemImpl__ctime(double time) diff --git a/OMCompiler/SimulationRuntime/c/util/omc_file.c b/OMCompiler/SimulationRuntime/c/util/omc_file.c index 36d85c6838d..29300b3c64f 100644 --- a/OMCompiler/SimulationRuntime/c/util/omc_file.c +++ b/OMCompiler/SimulationRuntime/c/util/omc_file.c @@ -240,11 +240,16 @@ int omc_unlink(const char *filename) { return result; } +// zero on success, anything else on failure! int omc_rename(const char *source, const char *dest) { #if defined(__MINGW32__) || defined(_MSC_VER) - return MoveFileEx(source, dest, MOVEFILE_REPLACE_EXISTING); + // If the function succeeds, the return value is nonzero. + // If the function fails, the return value is zero (0). To get extended error information, call GetLastError. + return !MoveFileEx(source, dest, MOVEFILE_REPLACE_EXISTING); #endif - return 0==rename(source,dest); + // On success, zero is returned. On error, -1 is returned, and + // errno is set to indicate the error. + return rename(source,dest); } #if defined(__MINGW32__) || defined(_MSC_VER)