3DS: Fix VDir3DS UTF-8 issues
Jeffrey Pfau jeffrey@endrift.com
Wed, 26 Aug 2015 21:34:13 -0700
2 files changed,
5 insertions(+),
11 deletions(-)
M
CMakeLists.txt
→
CMakeLists.txt
@@ -183,6 +183,7 @@ execute_process(COMMAND ${RAW2C} ${CMAKE_SOURCE_DIR}/src/platform/3ds/font.raw)
include_directories(${CMAKE_BINARY_DIR}) list(APPEND OS_LIB sf2d ctru) file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/3ds/*.c ${CMAKE_BINARY_DIR}/font.c) + set(USE_VFS_3DS ON) if(USE_VFS_3DS) add_definitions(-DUSE_VFS_3DS) else()
M
src/platform/3ds/3ds-vfs.c
→
src/platform/3ds/3ds-vfs.c
@@ -19,7 +19,7 @@
struct VDirEntry3DS { struct VDirEntry d; FS_dirent ent; - char* utf8Name; + char utf8Name[256]; }; struct VDir3DS {@@ -188,7 +188,6 @@ vd3d->d.openFile = _vd3dOpenFile;
vd3d->vde.d.name = _vd3deName; vd3d->vde.d.type = _vd3deType; - vd3d->vde.utf8Name = 0; return &vd3d->d; }@@ -197,9 +196,6 @@ static bool _vd3dClose(struct VDir* vd) {
struct VDir3DS* vd3d = (struct VDir3DS*) vd; FSDIR_Close(vd3d->handle); free(vd3d->path); - if (vd3d->vde.utf8Name) { - free(vd3d->vde.utf8Name); - } free(vd3d); return true; }@@ -215,10 +211,7 @@ static struct VDirEntry* _vd3dListNext(struct VDir* vd) {
struct VDir3DS* vd3d = (struct VDir3DS*) vd; u32 n = 0; memset(&vd3d->vde.ent, 0, sizeof(vd3d->vde.ent)); - if (vd3d->vde.utf8Name) { - free(vd3d->vde.utf8Name); - vd3d->vde.utf8Name = 0; - }; + memset(vd3d->vde.utf8Name, 0, sizeof(vd3d->vde.utf8Name)); FSDIR_Read(vd3d->handle, &n, 1, &vd3d->vde.ent); if (!n) { return 0;@@ -242,8 +235,8 @@ }
static const char* _vd3deName(struct VDirEntry* vde) { struct VDirEntry3DS* vd3de = (struct VDirEntry3DS*) vde; - if (!vd3de->utf8Name) { - vd3de->utf8Name = utf16to8(vd3de->ent.name, sizeof(vd3de->ent.name) / 2); + if (!vd3de->utf8Name[0]) { + utf16_to_utf8(vd3de->utf8Name, vd3de->ent.name, sizeof(vd3de->ent.name)); } return vd3de->utf8Name; }