Skip to content

Commit

Permalink
fix the fix for #9791 - proper return values! (#9794)
Browse files Browse the repository at this point in the history
- omc_rename returns zero on success
- SystemImpl__rename returns true on success
  • Loading branch information
adrpo committed Nov 28, 2022
1 parent 7c43b35 commit 74d05a3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Util/System.mo
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/runtime/systemimpl.c
Expand Up @@ -2992,7 +2992,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)
Expand Down
9 changes: 7 additions & 2 deletions OMCompiler/SimulationRuntime/c/util/omc_file.c
Expand Up @@ -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)
Expand Down

0 comments on commit 74d05a3

Please sign in to comment.