diff --git a/lfs.c b/lfs.c index 117595e0..86a1e147 100644 --- a/lfs.c +++ b/lfs.c @@ -1399,7 +1399,8 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir, LFS_MKTAG(0x780, 0, 0), LFS_MKTAG(LFS_TYPE_NAME, 0, namelen), // are we last name? - (strchr(name, '/') == NULL) ? id : NULL, + (strcspn(name, "/") + strspn(name + strcspn(name, "/"), "/") + == strlen(name)) ? id : NULL, lfs_dir_find_match, &(struct lfs_dir_find_match){ lfs, name, namelen}); if (tag < 0) { @@ -2408,7 +2409,8 @@ static int lfs_rawmkdir(lfs_t *lfs, const char *path) { } // check that name fits - lfs_size_t nlen = strlen(path); + // if name ends with slash, ignore it + lfs_size_t nlen = strcspn(path, "/"); if (nlen > lfs->name_max) { return LFS_ERR_NAMETOOLONG; }