From 4e51a1f690a213e7bc019481f09471f19dbb794b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E6=98=95?= Date: Mon, 16 May 2022 20:47:47 +0800 Subject: [PATCH] support slash-ended mkdir, such as "mkdir dir/". MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 田昕 --- lfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; }