From f2e704b9a7805e201a2a04781f1b1cd0c751ecc0 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 30 May 2023 22:37:33 +0200 Subject: [PATCH] Codechange: use std::string for FiosIsRoot --- src/fios.cpp | 4 ++-- src/os/os2/os2.cpp | 4 ++-- src/os/unix/unix.cpp | 4 ++-- src/os/windows/win32.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fios.cpp b/src/fios.cpp index 2f33f40cfc..5a9e30dbb6 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -35,7 +35,7 @@ static std::string *_fios_path = nullptr; SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING; /* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */ -extern bool FiosIsRoot(const char *path); +extern bool FiosIsRoot(const std::string &path); extern bool FiosIsValidFile(const std::string &path, const struct dirent *ent, struct stat *sb); extern bool FiosIsHiddenFile(const struct dirent *ent); extern void FiosGetDrives(FileList &file_list); @@ -366,7 +366,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c assert(_fios_path != nullptr); /* A parent directory link exists if we are not in the root directory */ - if (!FiosIsRoot(_fios_path->c_str())) { + if (!FiosIsRoot(*_fios_path)) { fios = &file_list.emplace_back(); fios->type = FIOS_TYPE_PARENT; fios->mtime = 0; diff --git a/src/os/os2/os2.cpp b/src/os/os2/os2.cpp index e3913d7289..bc7ffdca99 100644 --- a/src/os/os2/os2.cpp +++ b/src/os/os2/os2.cpp @@ -36,9 +36,9 @@ # include #endif -bool FiosIsRoot(const char *file) +bool FiosIsRoot(const std::string &file) { - return file[3] == '\0'; + return file.size() == 3; // C:\... } void FiosGetDrives(FileList &file_list) diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 0f18a977e1..aa3c443e15 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -57,9 +57,9 @@ #include "../../safeguards.h" -bool FiosIsRoot(const char *path) +bool FiosIsRoot(const std::string &path) { - return path[1] == '\0'; + return path == PATHSEP; } void FiosGetDrives(FileList &file_list) diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 54bf06249f..caf968f31e 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -168,9 +168,9 @@ int closedir(DIR *d) return 0; } -bool FiosIsRoot(const char *file) +bool FiosIsRoot(const std::string &file) { - return file[3] == '\0'; // C:\... + return file.size() == 3; // C:\... } void FiosGetDrives(FileList &file_list)