From e3d6486f2a730a101a2c3fd639684faf1d6a197f Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Sat, 11 Mar 2017 13:47:18 +0100 Subject: [PATCH] Move GetRelativePath to C4Language C4Language is the only consumer of GetRelativePath. It cannot handle arbitrarily sized paths, so discourage new code from using it by moving it to C4Language.cpp. Also remove the buffer size parameter which was always defaulted anyway and use template parameter deduction to always get the correct size. --- src/c4group/C4Language.cpp | 11 +++++++++++ src/platform/StdFile.cpp | 10 ---------- src/platform/StdFile.h | 1 - 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/c4group/C4Language.cpp b/src/c4group/C4Language.cpp index a45c254ff..1cf9aa8ee 100644 --- a/src/c4group/C4Language.cpp +++ b/src/c4group/C4Language.cpp @@ -31,6 +31,17 @@ #include "config/C4Config.h" #include "game/C4Game.h" +template +static bool GetRelativePath(const char *strPath, const char *strRelativeTo, char(&strBuffer)[iBufferSize]) +{ + // Specified path is relative to base path + // Copy relative section + const char *szCpy; + SCopy(szCpy = GetRelativePathS(strPath, strRelativeTo), strBuffer, iBufferSize); + // return whether it was made relative + return szCpy != strPath; +} + C4Language Languages; C4Language::C4Language() diff --git a/src/platform/StdFile.cpp b/src/platform/StdFile.cpp index 97f428cd5..9f338c409 100644 --- a/src/platform/StdFile.cpp +++ b/src/platform/StdFile.cpp @@ -218,16 +218,6 @@ bool GetParentPath(const char *szFilename, StdStrBuf *outBuf) return true; } -bool GetRelativePath(const char *strPath, const char *strRelativeTo, char *strBuffer, int iBufferSize) -{ - // Specified path is relative to base path - // Copy relative section - const char *szCpy; - SCopy(szCpy=GetRelativePathS(strPath, strRelativeTo), strBuffer, iBufferSize); - // return whether it was made relative - return szCpy!=strPath; -} - const char *GetRelativePathS(const char *strPath, const char *strRelativeTo) { // Specified path is relative to base path diff --git a/src/platform/StdFile.h b/src/platform/StdFile.h index 41d9a2d83..a54095b23 100644 --- a/src/platform/StdFile.h +++ b/src/platform/StdFile.h @@ -54,7 +54,6 @@ bool TruncatePath(char *szPath); // szBuffer has to be of at least _MAX_PATH length. bool GetParentPath(const char *szFilename, char *szBuffer); bool GetParentPath(const char *szFilename, StdStrBuf *outBuf); -bool GetRelativePath(const char *strPath, const char *strRelativeTo, char *strBuffer, int iBufferSize=_MAX_PATH); const char *GetRelativePathS(const char *strPath, const char *strRelativeTo); bool IsGlobalPath(const char *szPath);