diff --git a/file_io.cpp b/file_io.cpp index e1d51b4..16b8c7c 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -90,10 +90,9 @@ static int FileIsZipped(char* path, char** zip_path, char** file_path) static char* make_fullpath(const char *path, int mode = 0) { - const char *root = getRootDir(); - if (strncasecmp(getRootDir(), path, strlen(root))) + if (path[0] != '/') { - sprintf(full_path, "%s/%s", (mode == -1) ? "" : root, path); + sprintf(full_path, "%s/%s", (mode == -1) ? "" : getRootDir(), path); } else { @@ -626,8 +625,7 @@ int FileWriteSec(fileTYPE *file, void *pBuffer) int FileSave(const char *name, void *pBuffer, int size) { - if(name[0] != '/') sprintf(full_path, "%s/%s", getRootDir(), name); - else strcpy(full_path, name); + make_fullpath(name); int fd = open(full_path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) @@ -650,18 +648,14 @@ int FileSave(const char *name, void *pBuffer, int size) int FileDelete(const char *name) { - if (name[0] != '/') sprintf(full_path, "%s/%s", getRootDir(), name); - else strcpy(full_path, name); - + make_fullpath(name); printf("delete %s\n", full_path); return !unlink(full_path); } int DirDelete(const char *name) { - if (name[0] != '/') sprintf(full_path, "%s/%s", getRootDir(), name); - else strcpy(full_path, name); - + make_fullpath(name); printf("rmdir %s\n", full_path); return !rmdir(full_path); } @@ -721,7 +715,7 @@ int PathIsDir(const char *name, int use_zip) int FileCanWrite(const char *name) { - sprintf(full_path, "%s/%s", getRootDir(), name); + make_fullpath(name); if (FileIsZipped(full_path, nullptr, nullptr)) { @@ -843,7 +837,7 @@ void FileGenerateSavestatePath(const char *name, char* out_name) uint32_t getFileType(const char *name) { - sprintf(full_path, "%s/%s", getRootDir(), name); + make_fullpath(name); struct stat64 st; if (stat64(full_path, &st)) return 0; @@ -939,7 +933,7 @@ const char *getRootDir() const char *getFullPath(const char *name) { - sprintf(full_path, "%s/%s", getRootDir(), name); + make_fullpath(name); return full_path; }