From 26e5104a963d818f10e0405a78132129540c31cc Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Thu, 1 Sep 2022 06:48:26 +0300 Subject: [PATCH] Add compat_strdup --- src/db.cc | 2 +- src/dfile.cc | 2 +- src/main.cc | 2 +- src/platform_compat.cc | 5 +++++ src/platform_compat.h | 1 + src/xfile.cc | 4 ++-- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/db.cc b/src/db.cc index 647a3fb..696ff0d 100644 --- a/src/db.cc +++ b/src/db.cc @@ -655,7 +655,7 @@ int fileNameListInit(const char* pattern, char*** fileNameListPtr, int a3, int a char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", fileName, extension); free(xlist->fileNames[length]); - xlist->fileNames[length] = strdup(path); + xlist->fileNames[length] = compat_strdup(path); length++; } } diff --git a/src/dfile.cc b/src/dfile.cc index c6b9492..569ba54 100644 --- a/src/dfile.cc +++ b/src/dfile.cc @@ -141,7 +141,7 @@ DBase* dbaseOpen(const char* filePath) goto err; } - dbase->path = strdup(filePath); + dbase->path = compat_strdup(filePath); dbase->dataOffset = fileSize - dbaseDataSize; fclose(stream); diff --git a/src/main.cc b/src/main.cc index 0e6645d..ffee147 100644 --- a/src/main.cc +++ b/src/main.cc @@ -230,7 +230,7 @@ int falloutMain(int argc, char** argv) } } - char* mapNameCopy = strdup(mapName != NULL ? mapName : _mainMap); + char* mapNameCopy = compat_strdup(mapName != NULL ? mapName : _mainMap); _main_load_new(mapNameCopy); free(mapNameCopy); diff --git a/src/platform_compat.cc b/src/platform_compat.cc index a46c55b..5f15704 100644 --- a/src/platform_compat.cc +++ b/src/platform_compat.cc @@ -286,3 +286,8 @@ void compat_windows_path_to_native(char* path) } #endif } + +char* compat_strdup(const char* string) +{ + return SDL_strdup(string); +} diff --git a/src/platform_compat.h b/src/platform_compat.h index 1516a09..5bb4f57 100644 --- a/src/platform_compat.h +++ b/src/platform_compat.h @@ -39,5 +39,6 @@ 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); +char* compat_strdup(const char* string); #endif /* PLATFORM_COMPAT_H */ diff --git a/src/xfile.cc b/src/xfile.cc index 585f1a5..40ce71d 100644 --- a/src/xfile.cc +++ b/src/xfile.cc @@ -512,7 +512,7 @@ bool xbaseOpen(const char* path) memset(xbase, 0, sizeof(*xbase)); - xbase->path = strdup(path); + xbase->path = compat_strdup(path); if (xbase->path == NULL) { free(xbase); return false; @@ -814,7 +814,7 @@ static bool xlistEnumerateHandler(XListEnumerationContext* context) xlist->fileNames = fileNames; - fileNames[xlist->fileNamesLength] = strdup(context->name); + fileNames[xlist->fileNamesLength] = compat_strdup(context->name); if (fileNames[xlist->fileNamesLength] == NULL) { xlistFree(xlist); xlist->fileNamesLength = -1;