summaryrefslogtreecommitdiff
path: root/src/fios.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-12-06 21:11:45 +0100
committerMichael Lutz <michi@icosahedron.de>2020-12-27 13:19:25 +0100
commit65f65ad2ad8f029b99ef60e931b6d86952777610 (patch)
treeb1c45eb3137d4b8a8de7bf8acc446c73b6c6afb8 /src/fios.cpp
parentf3326d34e78bd28fba6d8cfd3bc455a506b429fe (diff)
downloadopenttd-65f65ad2ad8f029b99ef60e931b6d86952777610.tar.xz
Codechange: Convert some more FIO functions to take std::string.
Diffstat (limited to 'src/fios.cpp')
-rw-r--r--src/fios.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index 4e2378a34..e7341b1f5 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -200,26 +200,26 @@ const char *FiosBrowseTo(const FiosItem *item)
/**
* Construct a filename from its components in destination buffer \a buf.
- * @param buf Destination buffer.
* @param path Directory path, may be \c nullptr.
* @param name Filename.
* @param ext Filename extension (use \c "" for no extension).
- * @param last Last element of buffer \a buf.
+ * @return The completed filename.
*/
-static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, const char *last)
+static std::string FiosMakeFilename(const std::string *path, const char *name, const char *ext)
{
+ std::string buf;
+
if (path != nullptr) {
- const char *buf_start = buf;
- buf = strecpy(buf, path, last);
+ buf = *path;
/* Remove trailing path separator, if present */
- if (buf > buf_start && buf[-1] == PATHSEPCHAR) buf--;
+ if (!buf.empty() && buf.back() == PATHSEPCHAR) buf.pop_back();
}
/* Don't append the extension if it is already there */
const char *period = strrchr(name, '.');
if (period != nullptr && strcasecmp(period, ext) == 0) ext = "";
- seprintf(buf, last, PATHSEP "%s%s", name, ext);
+ return buf + name + ext;
}
/**
@@ -227,27 +227,26 @@ static void FiosMakeFilename(char *buf, const char *path, const char *name, cons
* @param buf Destination buffer for saving the filename.
* @param name Name of the file.
* @param last Last element of buffer \a buf.
+ * @return The completed filename.
*/
-void FiosMakeSavegameName(char *buf, const char *name, const char *last)
+std::string FiosMakeSavegameName(const char *name)
{
const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
- FiosMakeFilename(buf, _fios_path->c_str(), name, extension, last);
+ return FiosMakeFilename(_fios_path, name, extension);
}
/**
* Construct a filename for a height map.
- * @param buf Destination buffer.
* @param name Filename.
- * @param last Last element of buffer \a buf.
+ * @return The completed filename.
*/
-void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
+std::string FiosMakeHeightmapName(const char *name)
{
- char ext[5];
- ext[0] = '.';
- strecpy(ext + 1, GetCurrentScreenshotExtension(), lastof(ext));
+ std::string ext(".");
+ ext += GetCurrentScreenshotExtension();
- FiosMakeFilename(buf, _fios_path->c_str(), name, ext, last);
+ return FiosMakeFilename(_fios_path, name, ext.c_str());
}
/**
@@ -257,10 +256,8 @@ void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
*/
bool FiosDelete(const char *name)
{
- char filename[512];
-
- FiosMakeSavegameName(filename, name, lastof(filename));
- return unlink(filename) == 0;
+ std::string filename = FiosMakeSavegameName(name);
+ return unlink(filename.c_str()) == 0;
}
typedef FiosType fios_getlist_callback_proc(SaveLoadOperation fop, const char *filename, const char *ext, char *title, const char *last);