Provide rename compatibility layer

This commit is contained in:
Alexander Batalov 2022-06-18 10:44:04 +03:00
parent 83417b2d6a
commit b53723bf38
4 changed files with 20 additions and 6 deletions

View File

@ -782,7 +782,7 @@ int automapSaveCurrent()
// NOTE: Not sure about the size.
char automapTmpPath[512];
sprintf(automapTmpPath, "%s\\%s\\%s", masterPatchesPath, "MAPS", AUTOMAP_TMP);
if (rename(automapTmpPath, automapDbPath) != 0) {
if (compat_rename(automapTmpPath, automapDbPath) != 0) {
debugPrint("\nAUTOMAP: Error renaming database!\n");
return -1;
}

View File

@ -2498,7 +2498,7 @@ int _SaveBackup()
File* stream1 = fileOpen(_str0, "rb");
if (stream1 != NULL) {
fileClose(stream1);
if (rename(_str0, _str1) != 0) {
if (compat_rename(_str0, _str1) != 0) {
return -1;
}
}
@ -2520,7 +2520,7 @@ int _SaveBackup()
strcat(_str0, fileList[index]);
_strmfe(_str1, _str0, "BAK");
if (rename(_str0, _str1) != 0) {
if (compat_rename(_str0, _str1) != 0) {
fileNameListFree(&fileList, 0);
return -1;
}
@ -2567,7 +2567,7 @@ int _RestoreSave()
_strmfe(_str1, _str0, "BAK");
compat_remove(_str0);
if (rename(_str1, _str0) != 0) {
if (compat_rename(_str1, _str0) != 0) {
_EraseSave();
return -1;
}
@ -2594,7 +2594,7 @@ int _RestoreSave()
strcat(_str0, fileList[index]);
_strmfe(_str1, _str0, "SAV");
compat_remove(_str1);
if (rename(_str0, _str1) != 0) {
if (compat_rename(_str0, _str1) != 0) {
// FIXME: Probably leaks fileList.
_EraseSave();
return -1;
@ -2616,7 +2616,7 @@ int _RestoreSave()
strcpy(_str1, _gmpath);
strcat(_str1, v2);
if (rename(_str0, _str1) != 0) {
if (compat_rename(_str0, _str1) != 0) {
_EraseSave();
return -1;
}

View File

@ -179,6 +179,19 @@ int compat_remove(const char* path)
return remove(nativePath);
}
int compat_rename(const char* oldFileName, const char* newFileName)
{
char nativeOldFileName[COMPAT_MAX_PATH];
strcpy(nativeOldFileName, oldFileName);
compat_windows_path_to_native(nativeOldFileName);
char nativeNewFileName[COMPAT_MAX_PATH];
strcpy(nativeNewFileName, newFileName);
compat_windows_path_to_native(nativeNewFileName);
return rename(nativeOldFileName, nativeNewFileName);
}
void compat_windows_path_to_native(char* path)
{
#ifndef _WIN32

View File

@ -37,6 +37,7 @@ unsigned int compat_timeGetTime();
FILE* compat_fopen(const char* path, const char* mode);
gzFile compat_gzopen(const char* path, const char* mode);
int compat_remove(const char* path);
int compat_rename(const char* oldFileName, const char* newFileName);
void compat_windows_path_to_native(char* path);
#endif /* PLATFORM_COMPAT_H */