Skip to content

Commit

Permalink
support slash-ended mkdir, such as "mkdir dir/".
Browse files Browse the repository at this point in the history
Signed-off-by: 田昕 <[email protected]>
  • Loading branch information
XinStellaris committed May 16, 2022
1 parent 40dba4a commit 4e51a1f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4e51a1f

Please sign in to comment.