diff options
-rw-r--r-- | arm9/source/devices/file.c | 8 | ||||
-rw-r--r-- | arm9/source/devices/file.h | 1 |
2 files changed, 8 insertions, 1 deletions
diff --git a/arm9/source/devices/file.c b/arm9/source/devices/file.c index c9b822c..1b10862 100644 --- a/arm9/source/devices/file.c +++ b/arm9/source/devices/file.c @@ -29,6 +29,7 @@ void fs_close(FileDevice *fs) { fs->length = 0; fs->child = NULL; fs->dir_i = 0; + fs->at_root = false; } void fs_clear(FileDevice *fs) { @@ -82,6 +83,8 @@ void fs_open_entry(FileDevice* fs, u8 *path) { while ((fs->child = readdir(fs->dir))) { fs->dir_i++; }; + // If this is not the root directory, reduce len by 2 for . and .. dirs. + if (path[1] == 0) { fs->at_root = true; } else { fs->dir_i -= 2; } fs->length = fs->dir_i; fs_select_child(fs, 0); pb_populate(&fs->path, path); @@ -113,9 +116,12 @@ void fs_open_entry(FileDevice* fs, u8 *path) { } void fs_select_child(FileDevice *fs, u32 pointer) { + // Increment past the . and .. directories. + if (!fs->at_root) { + pointer += 2; + } fs->pointer = pointer; rewinddir(fs->dir); - fs->dir_i = 0; for (fs->dir_i=0; fs->dir_i<pointer+1; fs->dir_i++) { fs->child = readdir(fs->dir); diff --git a/arm9/source/devices/file.h b/arm9/source/devices/file.h index 86ca039..efff684 100644 --- a/arm9/source/devices/file.h +++ b/arm9/source/devices/file.h @@ -29,6 +29,7 @@ FILE *tmpfile; // to open file and keep existing file open struct dirent *child; // currently-selected directory child information u32 dir_i; // index of next child to read from dir + bool at_root; // current entry is the root directory } FileDevice; void init_filesystem(); |