diff --git a/OMCompiler/Compiler/runtime/om_curl.c b/OMCompiler/Compiler/runtime/om_curl.c index bf01d92ae6f..fcd403c4fa8 100644 --- a/OMCompiler/Compiler/runtime/om_curl.c +++ b/OMCompiler/Compiler/runtime/om_curl.c @@ -132,7 +132,7 @@ int om_curl_multi_download(void *urlPathList, int maxParallel) } } else { fclose(fout); - if (rename(MMC_STRINGDATA(p->tmpFilename), MMC_STRINGDATA(p->filename))) { + if (omc_rename(MMC_STRINGDATA(p->tmpFilename), MMC_STRINGDATA(p->filename))) { const char *msgs[3] = {strerror(errno), MMC_STRINGDATA(p->filename), MMC_STRINGDATA(p->tmpFilename)}; c_add_message(NULL, -1, ErrorType_runtime,ErrorLevel_error, "Failed to rename file after downloading with curl %s %s: %s", msgs, 3); } diff --git a/OMCompiler/Compiler/runtime/systemimpl.c b/OMCompiler/Compiler/runtime/systemimpl.c index fba875ca800..12b23fcfde4 100644 --- a/OMCompiler/Compiler/runtime/systemimpl.c +++ b/OMCompiler/Compiler/runtime/systemimpl.c @@ -2992,10 +2992,7 @@ int SystemImpl__fileContentsEqual(const char *file1, const char *file2) int SystemImpl__rename(const char *source, const char *dest) { -#if defined(__MINGW32__) || defined(_MSC_VER) - return MoveFileEx(source, dest, MOVEFILE_REPLACE_EXISTING); -#endif - return 0==rename(source,dest); + return omc_rename(source, dest); } char* SystemImpl__ctime(double time) diff --git a/OMCompiler/Compiler/runtime/systemimpl.h b/OMCompiler/Compiler/runtime/systemimpl.h index 972de9ae70c..77dbf6a0bf0 100644 --- a/OMCompiler/Compiler/runtime/systemimpl.h +++ b/OMCompiler/Compiler/runtime/systemimpl.h @@ -92,6 +92,7 @@ extern int SystemImpl__setLDFlags(const char *str); extern char* SystemImpl__pwd(void); extern int SystemImpl__regularFileExists(const char* str); extern int SystemImpl__removeFile(const char* filename); +extern int SystemImpl__rename(const char *source, const char *dest); extern const char* SystemImpl__basename(const char *str); extern int SystemImpl__systemCall(const char* str, const char* outFile); extern void* SystemImpl__systemCallParallel(void *lst, int numThreads); diff --git a/OMCompiler/SimulationRuntime/c/util/omc_file.c b/OMCompiler/SimulationRuntime/c/util/omc_file.c index ff2ba27859b..36d85c6838d 100644 --- a/OMCompiler/SimulationRuntime/c/util/omc_file.c +++ b/OMCompiler/SimulationRuntime/c/util/omc_file.c @@ -217,8 +217,7 @@ int omc_file_exists(const char* filename) { * @param filename File name * @return int 0 on success, -1 on error. */ -int omc_unlink(const char *filename) -{ +int omc_unlink(const char *filename) { int result = 0; #if defined(__MINGW32__) || defined(_MSC_VER) wchar_t* unicodeFilename = omc_multibyte_to_wchar_str(filename); @@ -241,6 +240,13 @@ int omc_unlink(const char *filename) return result; } +int omc_rename(const char *source, const char *dest) { +#if defined(__MINGW32__) || defined(_MSC_VER) + return MoveFileEx(source, dest, MOVEFILE_REPLACE_EXISTING); +#endif + return 0==rename(source,dest); +} + #if defined(__MINGW32__) || defined(_MSC_VER) /** * @brief Return long absolute path from given path. diff --git a/OMCompiler/SimulationRuntime/c/util/omc_file.h b/OMCompiler/SimulationRuntime/c/util/omc_file.h index 0c2f18f57af..7b78b86dbcb 100644 --- a/OMCompiler/SimulationRuntime/c/util/omc_file.h +++ b/OMCompiler/SimulationRuntime/c/util/omc_file.h @@ -90,6 +90,7 @@ int omc_lstat(const char *filename, omc_stat_t *statbuf); int omc_file_exists(const char* filename); int omc_unlink(const char *filename); +int omc_rename(const char *source, const char *dest); #if defined(__MINGW32__) || defined(_MSC_VER) wchar_t* longabspath(wchar_t* unicodePath);