diff options
-rw-r--r-- | src/fileio.cpp | 75 | ||||
-rw-r--r-- | src/fileio_func.h | 10 | ||||
-rw-r--r-- | src/fios.cpp | 72 | ||||
-rw-r--r-- | src/fios.h | 4 | ||||
-rw-r--r-- | src/fios_gui.cpp | 10 | ||||
-rw-r--r-- | src/music_gui.cpp | 4 | ||||
-rw-r--r-- | src/network/network_content.cpp | 2 | ||||
-rw-r--r-- | src/script/script_instance.cpp | 2 | ||||
-rw-r--r-- | src/strings.cpp | 2 | ||||
-rw-r--r-- | src/video/sdl_v.cpp | 2 |
10 files changed, 95 insertions, 88 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp index b7226f5cc..da49f47e5 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -344,30 +344,30 @@ void FioFCloseFile(FILE *f) fclose(f); } -char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename) +char *FioGetFullPath(char *buf, const char *last, Searchpath sp, Subdirectory subdir, const char *filename) { assert(subdir < NUM_SUBDIRS); assert(sp < NUM_SEARCHPATHS); - snprintf(buf, buflen, "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename); + seprintf(buf, last, "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename); return buf; } /** * Find a path to the filename in one of the search directories. * @param buf [out] Destination buffer for the path. - * @param buflen Length of the destination buffer. + * @param last End of the destination buffer. * @param subdir Subdirectory to try. * @param filename Filename to look for. * @return \a buf containing the path if the path was found, else \c NULL. */ -char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename) +char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename) { Searchpath sp; assert(subdir < NUM_SUBDIRS); FOR_ALL_SEARCHPATHS(sp) { - FioGetFullPath(buf, buflen, sp, subdir, filename); + FioGetFullPath(buf, last, sp, subdir, filename); if (FileExists(buf)) return buf; #if !defined(WIN32) /* Be, as opening files, aware that sometimes the filename @@ -380,27 +380,27 @@ char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char return NULL; } -char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir) +char *FioAppendDirectory(char *buf, const char *last, Searchpath sp, Subdirectory subdir) { assert(subdir < NUM_SUBDIRS); assert(sp < NUM_SEARCHPATHS); - snprintf(buf, buflen, "%s%s", _searchpaths[sp], _subdirs[subdir]); + seprintf(buf, last, "%s%s", _searchpaths[sp], _subdirs[subdir]); return buf; } -char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir) +char *FioGetDirectory(char *buf, const char *last, Subdirectory subdir) { Searchpath sp; /* Find and return the first valid directory */ FOR_ALL_SEARCHPATHS(sp) { - char *ret = FioAppendDirectory(buf, buflen, sp, subdir); + char *ret = FioAppendDirectory(buf, last, sp, subdir); if (FileExists(buf)) return ret; } /* Could not find the directory, fall back to a base path */ - strecpy(buf, _personal_dir, &buf[buflen - 1]); + strecpy(buf, _personal_dir, last); return buf; } @@ -421,7 +421,7 @@ static FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath s if (subdir == NO_DIRECTORY) { strecpy(buf, filename, lastof(buf)); } else { - snprintf(buf, lengthof(buf), "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename); + seprintf(buf, lastof(buf), "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename); } #if defined(WIN32) @@ -566,20 +566,19 @@ static void FioCreateDirectory(const char *name) /** * Appends, if necessary, the path separator character to the end of the string. * It does not add the path separator to zero-sized strings. - * @param buf string to append the separator to - * @param buflen the length of \a buf. + * @param buf string to append the separator to + * @param last the last element of \a buf. * @return true iff the operation succeeded */ -bool AppendPathSeparator(char *buf, size_t buflen) +bool AppendPathSeparator(char *buf, const char *last) { size_t s = strlen(buf); /* Length of string + path separator + '\0' */ if (s != 0 && buf[s - 1] != PATHSEPCHAR) { - if (s + 2 >= buflen) return false; + if (&buf[s] >= last) return false; - buf[s] = PATHSEPCHAR; - buf[s + 1] = '\0'; + seprintf(buf + s, last, "%c", PATHSEPCHAR); } return true; @@ -603,10 +602,10 @@ char *BuildWithFullPath(const char *dir) /* Add absolute path */ if (s == NULL || dest != s) { if (getcwd(dest, MAX_PATH) == NULL) *dest = '\0'; - AppendPathSeparator(dest, MAX_PATH); + AppendPathSeparator(dest, last); strecat(dest, dir, last); } - AppendPathSeparator(dest, MAX_PATH); + AppendPathSeparator(dest, last); return dest; } @@ -1073,8 +1072,8 @@ bool DoScanWorkingDirectory() if (_searchpaths[SP_PERSONAL_DIR] == NULL) return true; char tmp[MAX_PATH]; - snprintf(tmp, lengthof(tmp), "%s%s", _searchpaths[SP_WORKING_DIR], PERSONAL_DIR); - AppendPathSeparator(tmp, MAX_PATH); + seprintf(tmp, lastof(tmp), "%s%s", _searchpaths[SP_WORKING_DIR], PERSONAL_DIR); + AppendPathSeparator(tmp, lastof(tmp)); return strcmp(tmp, _searchpaths[SP_PERSONAL_DIR]) != 0; } @@ -1087,11 +1086,11 @@ void DetermineBasePaths(const char *exe) char tmp[MAX_PATH]; #if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR) const char *xdg_data_home = xdgDataHome(NULL); - snprintf(tmp, MAX_PATH, "%s" PATHSEP "%s", xdg_data_home, + seprintf(tmp, lastof(tmp), "%s" PATHSEP "%s", xdg_data_home, PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR); free(xdg_data_home); - AppendPathSeparator(tmp, MAX_PATH); + AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_PERSONAL_DIR_XDG] = strdup(tmp); #endif #if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR) @@ -1119,8 +1118,8 @@ void DetermineBasePaths(const char *exe) if (homedir != NULL) { ValidateString(homedir); - snprintf(tmp, MAX_PATH, "%s" PATHSEP "%s", homedir, PERSONAL_DIR); - AppendPathSeparator(tmp, MAX_PATH); + seprintf(tmp, lastof(tmp), "%s" PATHSEP "%s", homedir, PERSONAL_DIR); + AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_PERSONAL_DIR] = strdup(tmp); free(homedir); @@ -1130,8 +1129,8 @@ void DetermineBasePaths(const char *exe) #endif #if defined(WITH_SHARED_DIR) - snprintf(tmp, MAX_PATH, "%s", SHARED_DIR); - AppendPathSeparator(tmp, MAX_PATH); + seprintf(tmp, lastof(tmp), "%s", SHARED_DIR); + AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_SHARED_DIR] = strdup(tmp); #else _searchpaths[SP_SHARED_DIR] = NULL; @@ -1141,7 +1140,7 @@ void DetermineBasePaths(const char *exe) _searchpaths[SP_WORKING_DIR] = NULL; #else if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; - AppendPathSeparator(tmp, MAX_PATH); + AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_WORKING_DIR] = strdup(tmp); #endif @@ -1150,7 +1149,7 @@ void DetermineBasePaths(const char *exe) /* Change the working directory to that one of the executable */ if (ChangeWorkingDirectoryToExecutable(exe)) { if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; - AppendPathSeparator(tmp, MAX_PATH); + AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_BINARY_DIR] = strdup(tmp); } else { _searchpaths[SP_BINARY_DIR] = NULL; @@ -1166,8 +1165,8 @@ void DetermineBasePaths(const char *exe) #if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) _searchpaths[SP_INSTALLATION_DIR] = NULL; #else - snprintf(tmp, MAX_PATH, "%s", GLOBAL_DATA_DIR); - AppendPathSeparator(tmp, MAX_PATH); + seprintf(tmp, lastof(tmp), "%s", GLOBAL_DATA_DIR); + AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_INSTALLATION_DIR] = strdup(tmp); #endif #ifdef WITH_COCOA @@ -1195,11 +1194,11 @@ void DeterminePaths(const char *exe) char config_home[MAX_PATH]; const char *xdg_config_home = xdgConfigHome(NULL); - snprintf(config_home, MAX_PATH, "%s" PATHSEP "%s", xdg_config_home, + seprintf(config_home, lastof(config_home), "%s" PATHSEP "%s", xdg_config_home, PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR); free(xdg_config_home); - AppendPathSeparator(config_home, MAX_PATH); + AppendPathSeparator(config_home, lastof(config_home)); #endif Searchpath sp; @@ -1219,7 +1218,7 @@ void DeterminePaths(const char *exe) } } else { char personal_dir[MAX_PATH]; - if (FioFindFullPath(personal_dir, lengthof(personal_dir), BASE_DIR, "openttd.cfg") != NULL) { + if (FioFindFullPath(personal_dir, lastof(personal_dir), BASE_DIR, "openttd.cfg") != NULL) { char *end = strrchr(personal_dir, PATHSEPCHAR); if (end != NULL) end[1] = '\0'; config_dir = strdup(personal_dir); @@ -1400,13 +1399,13 @@ static uint ScanPath(FileScanner *fs, const char *extension, const char *path, s if (!FiosIsValidFile(path, dirent, &sb)) continue; - snprintf(filename, lengthof(filename), "%s%s", path, d_name); + seprintf(filename, lastof(filename), "%s%s", path, d_name); if (S_ISDIR(sb.st_mode)) { /* Directory */ if (!recursive) continue; if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; - if (!AppendPathSeparator(filename, lengthof(filename))) continue; + if (!AppendPathSeparator(filename, lastof(filename))) continue; num += ScanPath(fs, extension, filename, basepath_length, recursive); } else if (S_ISREG(sb.st_mode)) { /* File */ @@ -1457,7 +1456,7 @@ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool r /* Don't search in the working directory */ if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue; - FioAppendDirectory(path, MAX_PATH, sp, sd); + FioAppendDirectory(path, lastof(path), sp, sd); num += ScanPath(this, extension, path, strlen(path), recursive); } @@ -1493,6 +1492,6 @@ uint FileScanner::Scan(const char *extension, const char *directory, bool recurs { char path[MAX_PATH]; strecpy(path, directory, lastof(path)); - if (!AppendPathSeparator(path, lengthof(path))) return 0; + if (!AppendPathSeparator(path, lastof(path))) return 0; return ScanPath(this, extension, path, strlen(path), recursive); } diff --git a/src/fileio_func.h b/src/fileio_func.h index 449ba51fe..443460b2d 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -51,15 +51,15 @@ static inline bool IsValidSearchPath(Searchpath sp) void FioFCloseFile(FILE *f); FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = NULL); bool FioCheckFileExists(const char *filename, Subdirectory subdir); -char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename); -char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename); -char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir); -char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir); +char *FioGetFullPath(char *buf, const char *last, Searchpath sp, Subdirectory subdir, const char *filename); +char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename); +char *FioAppendDirectory(char *buf, const char *last, Searchpath sp, Subdirectory subdir); +char *FioGetDirectory(char *buf, const char *last, Subdirectory subdir); const char *FiosGetScreenshotDir(); void SanitizeFilename(char *filename); -bool AppendPathSeparator(char *buf, size_t buflen); +bool AppendPathSeparator(char *buf, const char *last); void DeterminePaths(const char *exe); void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize); bool FileExists(const char *filename); diff --git a/src/fios.cpp b/src/fios.cpp index ced425967..43d781b5d 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -31,6 +31,7 @@ /* Variables to display file lists */ SmallVector<FiosItem, 32> _fios_items; static char *_fios_path; +static const char *_fios_path_last; SmallFiosItem _file_to_saveload; SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING; @@ -91,14 +92,12 @@ StringID FiosGetDescText(const char **path, uint64 *total_free) */ const char *FiosBrowseTo(const FiosItem *item) { - char *path = _fios_path; - switch (item->type) { case FIOS_TYPE_DRIVE: #if defined(WINCE) - snprintf(path, MAX_PATH, PATHSEP ""); + seprintf(_fios_path, _fios_path_last, PATHSEP ""); #elif defined(WIN32) || defined(__OS2__) - snprintf(path, MAX_PATH, "%c:" PATHSEP, item->title[0]); + seprintf(_fios_path, _fios_path_last, "%c:" PATHSEP, item->title[0]); #endif /* FALL THROUGH */ case FIOS_TYPE_INVALID: @@ -106,16 +105,16 @@ const char *FiosBrowseTo(const FiosItem *item) case FIOS_TYPE_PARENT: { /* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */ - char *s = strrchr(path, PATHSEPCHAR); - if (s != NULL && s != path) { + char *s = strrchr(_fios_path, PATHSEPCHAR); + if (s != NULL && s != _fios_path) { s[0] = '\0'; // Remove last path separator character, so we can go up one level. } - s = strrchr(path, PATHSEPCHAR); + s = strrchr(_fios_path, PATHSEPCHAR); if (s != NULL) { s[1] = '\0'; // go up a directory #if defined(__MORPHOS__) || defined(__AMIGAOS__) /* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */ - } else if ((s = strrchr(path, ':')) != NULL) { + } else if ((s = strrchr(_fios_path, ':')) != NULL) { s[1] = '\0'; #endif } @@ -123,12 +122,12 @@ const char *FiosBrowseTo(const FiosItem *item) } case FIOS_TYPE_DIR: - strcat(path, item->name); - strcat(path, PATHSEP); + strecat(_fios_path, item->name, _fios_path_last); + strecat(_fios_path, PATHSEP, _fios_path_last); break; case FIOS_TYPE_DIRECT: - snprintf(path, MAX_PATH, "%s", item->name); + seprintf(_fios_path, _fios_path_last, "%s", item->name); break; case FIOS_TYPE_FILE: @@ -149,9 +148,9 @@ const char *FiosBrowseTo(const FiosItem *item) * @param path Directory path, may be \c NULL. * @param name Filename. * @param ext Filename extension (use \c "" for no extension). - * @param size Size of \a buf. + * @param last Last element of buffer \a buf. */ -static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, size_t size) +static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, const char *last) { const char *period; @@ -163,15 +162,15 @@ static void FiosMakeFilename(char *buf, const char *path, const char *name, cons unsigned char sepchar = path[(strlen(path) - 1)]; if (sepchar != ':' && sepchar != '/') { - snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext); + seprintf(buf, last, "%s" PATHSEP "%s%s", path, name, ext); } else { - snprintf(buf, size, "%s%s%s", path, name, ext); + seprintf(buf, last, "%s%s%s", path, name, ext); } } else { - snprintf(buf, size, "%s%s", name, ext); + seprintf(buf, last, "%s%s", name, ext); } #else - snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext); + seprintf(buf, last, "%s" PATHSEP "%s%s", path, name, ext); #endif } @@ -179,28 +178,28 @@ static void FiosMakeFilename(char *buf, const char *path, const char *name, cons * Make a save game or scenario filename from a name. * @param buf Destination buffer for saving the filename. * @param name Name of the file. - * @param size Length of buffer \a buf. + * @param last Last element of buffer \a buf. */ -void FiosMakeSavegameName(char *buf, const char *name, size_t size) +void FiosMakeSavegameName(char *buf, const char *name, const char *last) { const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav"; - FiosMakeFilename(buf, _fios_path, name, extension, size); + FiosMakeFilename(buf, _fios_path, name, extension, _fios_path_last); } /** * Construct a filename for a height map. * @param buf Destination buffer. * @param name Filename. - * @param size Size of \a buf. + * @param last Last element of buffer \a buf. */ -void FiosMakeHeightmapName(char *buf, const char *name, size_t size) +void FiosMakeHeightmapName(char *buf, const char *name, const char *last) { char ext[5]; ext[0] = '.'; strecpy(ext + 1, GetCurrentScreenshotExtension(), lastof(ext)); - FiosMakeFilename(buf, _fios_path, name, ext, size); + FiosMakeFilename(buf, _fios_path, name, ext, _fios_path_last); } /** @@ -211,7 +210,7 @@ bool FiosDelete(const char *name) { char filename[512]; - FiosMakeSavegameName(filename, name, lengthof(filename)); + FiosMakeSavegameName(filename, name, lastof(filename)); return unlink(filename) == 0; } @@ -326,7 +325,7 @@ static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc fios->type = FIOS_TYPE_DIR; fios->mtime = 0; strecpy(fios->name, d_name, lastof(fios->name)); - snprintf(fios->title, lengthof(fios->title), "%s" PATHSEP " (Directory)", d_name); + seprintf(fios->title, lastof(fios->title), "%s" PATHSEP " (Directory)", d_name); str_validate(fios->title, lastof(fios->title)); } } @@ -430,13 +429,16 @@ FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, void FiosGetSavegameList(SaveLoadDialogMode mode) { static char *fios_save_path = NULL; + static char *fios_save_path_last = NULL; if (fios_save_path == NULL) { fios_save_path = MallocT<char>(MAX_PATH); - FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR); + fios_save_path_last = fios_save_path + MAX_PATH - 1; + FioGetDirectory(fios_save_path, fios_save_path_last, SAVE_DIR); } _fios_path = fios_save_path; + _fios_path_last = fios_save_path_last; FiosGetFileList(mode, &FiosGetSavegameListCallback, NO_DIRECTORY); } @@ -481,17 +483,20 @@ static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char void FiosGetScenarioList(SaveLoadDialogMode mode) { static char *fios_scn_path = NULL; + static char *fios_scn_path_last = NULL; /* Copy the default path on first run or on 'New Game' */ if (fios_scn_path == NULL) { fios_scn_path = MallocT<char>(MAX_PATH); - FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR); + fios_scn_path_last = fios_scn_path + MAX_PATH - 1; + FioGetDirectory(fios_scn_path, fios_scn_path_last, SCENARIO_DIR); } _fios_path = fios_scn_path; + _fios_path_last = fios_scn_path_last; char base_path[MAX_PATH]; - FioGetDirectory(base_path, sizeof(base_path), SCENARIO_DIR); + FioGetDirectory(base_path, lastof(base_path), SCENARIO_DIR); FiosGetFileList(mode, &FiosGetScenarioListCallback, (mode == SLD_LOAD_SCENARIO && strcmp(base_path, _fios_path) == 0) ? SCENARIO_DIR : NO_DIRECTORY); } @@ -524,7 +529,7 @@ static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char Searchpath sp; FOR_ALL_SEARCHPATHS(sp) { char buf[MAX_PATH]; - FioAppendDirectory(buf, sizeof(buf), sp, HEIGHTMAP_DIR); + FioAppendDirectory(buf, lastof(buf), sp, HEIGHTMAP_DIR); if (strncmp(buf, it->second.tar_filename, strlen(buf)) == 0) { match = true; @@ -547,16 +552,19 @@ static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char void FiosGetHeightmapList(SaveLoadDialogMode mode) { static char *fios_hmap_path = NULL; + static char *fios_hmap_path_last = NULL; if (fios_hmap_path == NULL) { fios_hmap_path = MallocT<char>(MAX_PATH); - FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR); + fios_hmap_path_last = fios_hmap_path + MAX_PATH - 1; + FioGetDirectory(fios_hmap_path, fios_hmap_path_last, HEIGHTMAP_DIR); } _fios_path = fios_hmap_path; + _fios_path_last = fios_hmap_path_last; char base_path[MAX_PATH]; - FioGetDirectory(base_path, sizeof(base_path), HEIGHTMAP_DIR); + FioGetDirectory(base_path, lastof(base_path), HEIGHTMAP_DIR); FiosGetFileList(mode, &FiosGetHeightmapListCallback, strcmp(base_path, _fios_path) == 0 ? HEIGHTMAP_DIR : NO_DIRECTORY); } @@ -571,7 +579,7 @@ const char *FiosGetScreenshotDir() if (fios_screenshot_path == NULL) { fios_screenshot_path = MallocT<char>(MAX_PATH); - FioGetDirectory(fios_screenshot_path, MAX_PATH, SCREENSHOT_DIR); + FioGetDirectory(fios_screenshot_path, fios_screenshot_path + MAX_PATH - 1, SCREENSHOT_DIR); } return fios_screenshot_path; diff --git a/src/fios.h b/src/fios.h index 43a018f26..b26fe0092 100644 --- a/src/fios.h +++ b/src/fios.h @@ -170,8 +170,8 @@ const char *FiosBrowseTo(const FiosItem *item); StringID FiosGetDescText(const char **path, uint64 *total_free); bool FiosDelete(const char *name); -void FiosMakeHeightmapName(char *buf, const char *name, size_t size); -void FiosMakeSavegameName(char *buf, const char *name, size_t size); +void FiosMakeHeightmapName(char *buf, const char *name, const char *last); +void FiosMakeSavegameName(char *buf, const char *name, const char *last); FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last); diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 579eedf89..5c91ec77d 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -298,17 +298,17 @@ public: switch (_saveload_mode) { case SLD_SAVE_GAME: case SLD_LOAD_GAME: - FioGetDirectory(o_dir.name, lengthof(o_dir.name), SAVE_DIR); + FioGetDirectory(o_dir.name, lastof(o_dir.name), SAVE_DIR); break; case SLD_SAVE_SCENARIO: case SLD_LOAD_SCENARIO: - FioGetDirectory(o_dir.name, lengthof(o_dir.name), SCENARIO_DIR); + FioGetDirectory(o_dir.name, lastof(o_dir.name), SCENARIO_DIR); break; case SLD_SAVE_HEIGHTMAP: case SLD_LOAD_HEIGHTMAP: - FioGetDirectory(o_dir.name, lengthof(o_dir.name), HEIGHTMAP_DIR); + FioGetDirectory(o_dir.name, lastof(o_dir.name), HEIGHTMAP_DIR); break; default: @@ -654,10 +654,10 @@ public: } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { _switch_mode = SM_SAVE_GAME; - FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name)); + FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); } else { _switch_mode = SM_SAVE_HEIGHTMAP; - FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name)); + FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); } /* In the editor set up the vehicle engines correctly (date might have changed) */ diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 01406849f..c9eb21aa3 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -182,8 +182,8 @@ static void MusicVolumeChanged(byte new_vol) static void DoPlaySong() { char filename[MAX_PATH]; - if (FioFindFullPath(filename, lengthof(filename), BASESET_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename) == NULL) { - FioFindFullPath(filename, lengthof(filename), OLD_GM_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename); + if (FioFindFullPath(filename, lastof(filename), BASESET_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename) == NULL) { + FioFindFullPath(filename, lastof(filename), OLD_GM_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename); } _music_driver->PlaySong(filename); SetWindowDirty(WC_MUSIC_WINDOW, 0); diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 215ed5dfd..174dbdafe 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -390,7 +390,7 @@ static char *GetFullFilename(const ContentInfo *ci, bool compressed) if (dir == NO_DIRECTORY) return NULL; static char buf[MAX_PATH]; - FioGetFullPath(buf, lengthof(buf), SP_AUTODOWNLOAD_DIR, dir, ci->filename); + FioGetFullPath(buf, lastof(buf), SP_AUTODOWNLOAD_DIR, dir, ci->filename); strecat(buf, compressed ? ".tar.gz" : ".tar", lastof(buf)); return buf; diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index eab85d74b..9cfe05c49 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -116,7 +116,7 @@ bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirect char buf[MAX_PATH]; Searchpath sp; FOR_ALL_SEARCHPATHS(sp) { - FioAppendDirectory(buf, MAX_PATH, sp, dir); + FioAppendDirectory(buf, lastof(buf), sp, dir); strecat(buf, script_name, lastof(buf)); if (!FileExists(buf)) continue; diff --git a/src/strings.cpp b/src/strings.cpp index 23a8804ab..1b95f4251 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1954,7 +1954,7 @@ void InitializeLanguagePacks() FOR_ALL_SEARCHPATHS(sp) { char path[MAX_PATH]; - FioAppendDirectory(path, lengthof(path), sp, LANG_DIR); + FioAppendDirectory(path, lastof(path), sp, LANG_DIR); GetLanguageList(path); } if (_languages.Length() == 0) usererror("No available language packs (invalid versions?)"); diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 6ec5269d5..9b1dd727f 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -282,7 +282,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); char icon_path[MAX_PATH]; - if (FioFindFullPath(icon_path, lengthof(icon_path), BASESET_DIR, "openttd.32.bmp") != NULL) { + if (FioFindFullPath(icon_path, lastof(icon_path), BASESET_DIR, "openttd.32.bmp") != NULL) { /* Give the application an icon */ icon = SDL_CALL SDL_LoadBMP(icon_path); if (icon != NULL) { |