1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

pkg/littlefs*: align readdir() with documentation

`readdir()` should only output the name of the file, but littleFS
adds a leading `/`.

Neither FAT nor Linux will exhibit this behavior.

        struct dirent *entry;
        DIR *dir = opendir(".");
        while ((entry = readdir(dir))) {
                printf("%s\n", entry->d_name);
        }

This results in surprising failures of code that expects filenames
to match that was tested on a different FS, when suddenly there is
a `/` in front of the filename.
This commit is contained in:
Benjamin Valentin 2022-02-07 23:25:14 +01:00
parent 865df2056b
commit 6a361795ee
2 changed files with 2 additions and 4 deletions

View File

@ -493,8 +493,7 @@ static int _readdir(vfs_DIR *dirp, vfs_dirent_t *entry)
int ret = lfs_dir_read(&fs->fs, dir, &info);
if (ret >= 0) {
entry->d_ino = info.type;
entry->d_name[0] = '/';
strncpy(entry->d_name + 1, info.name, VFS_NAME_MAX - 1);
strncpy(entry->d_name, info.name, VFS_NAME_MAX - 1);
}
mutex_unlock(&fs->lock);

View File

@ -499,8 +499,7 @@ static int _readdir(vfs_DIR *dirp, vfs_dirent_t *entry)
int ret = lfs_dir_read(&fs->fs, dir, &info);
if (ret >= 0) {
entry->d_ino = info.type;
entry->d_name[0] = '/';
strncpy(entry->d_name + 1, info.name, VFS_NAME_MAX - 1);
strncpy(entry->d_name, info.name, VFS_NAME_MAX - 1);
}
mutex_unlock(&fs->lock);