Skip to content

Commit d9d729d

Browse files
committed
FS: fix FS::Stat function by looking at local dir instead of /
Like in `FileOpen()` interpret filenames starting with `/` as paths relative to the current working directory by removing the first `/` from the path. Fixes: #23
1 parent de8d0d6 commit d9d729d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

sim/components/fs/FS.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ int FS::DirDelete(const char* path) {
165165

166166
// check if file exists, if so write file-size into info object
167167
int FS::Stat(const char* path, lfs_info* info) {
168-
if (!std::filesystem::exists(path))
168+
const char *local_filename = path[0]=='/' ? &path[1] : path;
169+
if (!std::filesystem::exists(local_filename))
169170
{
170171
return LFS_ERR_NOENT; // No directory entry
171172
}
172-
info->size = std::filesystem::file_size(path);
173+
info->size = std::filesystem::file_size(local_filename);
173174
return LFS_ERR_OK;
174175
}
175176

0 commit comments

Comments
 (0)