all repos — mgba @ ef93f686580686e35044a0f620c37f3ddf850d18

mGBA Game Boy Advance Emulator

VFS: Move VDirOptionalOpenFile back to vfs.c
Jeffrey Pfau jeffrey@endrift.com
Sat, 20 Jun 2015 03:17:05 -0700
commit

ef93f686580686e35044a0f620c37f3ddf850d18

parent

43f9f2dfd314841156f5b0f8fb6ed1478ff29dd9

2 files changed, 28 insertions(+), 28 deletions(-)

jump to
M src/util/vfs.csrc/util/vfs.c

@@ -80,3 +80,31 @@ STORE_16LE(lehword, 0, hword);

} return r; } + +struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode) { + char path[PATH_MAX]; + path[PATH_MAX - 1] = '\0'; + struct VFile* vf; + if (!dir) { + if (!realPath) { + return 0; + } + char* dotPoint = strrchr(realPath, '.'); + if (dotPoint - realPath + 1 >= PATH_MAX - 1) { + return 0; + } + if (dotPoint > strrchr(realPath, '/')) { + int len = dotPoint - realPath; + strncpy(path, realPath, len); + path[len] = 0; + strncat(path + len, suffix, PATH_MAX - len - 1); + } else { + snprintf(path, PATH_MAX - 1, "%s%s", realPath, suffix); + } + vf = VFileOpen(path, mode); + } else { + snprintf(path, PATH_MAX - 1, "%s%s", prefix, suffix); + vf = dir->openFile(dir, path, mode); + } + return vf; +}
M src/util/vfs/vfs-dirent.csrc/util/vfs/vfs-dirent.c

@@ -190,31 +190,3 @@ return vdede->ent->d_name;

} return 0; } - -struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode) { - char path[PATH_MAX]; - path[PATH_MAX - 1] = '\0'; - struct VFile* vf; - if (!dir) { - if (!realPath) { - return 0; - } - char* dotPoint = strrchr(realPath, '.'); - if (dotPoint - realPath + 1 >= PATH_MAX - 1) { - return 0; - } - if (dotPoint > strrchr(realPath, '/')) { - int len = dotPoint - realPath; - strncpy(path, realPath, len); - path[len] = 0; - strncat(path + len, suffix, PATH_MAX - len - 1); - } else { - snprintf(path, PATH_MAX - 1, "%s%s", realPath, suffix); - } - vf = VFileOpen(path, mode); - } else { - snprintf(path, PATH_MAX - 1, "%s%s", prefix, suffix); - vf = dir->openFile(dir, path, mode); - } - return vf; -}