Skip to content

Commit da15101

Browse files
CopilotJohnAmadis
andcommitted
Fix readdir to return basename only, not full path
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 6c25575 commit da15101

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/dmdevfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _readdir, (dmfsi_context_t ct
647647
bool file_should_be_listed = compare_paths_ignore_trailing_slash(dir_node->directory_path, parent_dir) == 0;
648648
if(file_should_be_listed)
649649
{
650-
strncpy(entry->name, driver->path, sizeof(entry->name));
650+
// Extract basename from the full path for the directory entry
651+
read_base_name(driver->path, entry->name, sizeof(entry->name));
651652

652653
dmdrvi_stat_t stat;
653654
int res = driver_stat(driver, driver->path, &stat);
@@ -662,7 +663,8 @@ dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _readdir, (dmfsi_context_t ct
662663
}
663664
else
664665
{
665-
strncpy(entry->name, parent_dir, sizeof(entry->name));
666+
// Extract basename from parent directory for subdirectory entries
667+
read_base_name(parent_dir, entry->name, sizeof(entry->name));
666668
entry->size = 0;
667669
entry->attr = DMFSI_ATTR_DIRECTORY;
668670
}

0 commit comments

Comments
 (0)