Skip to content

Commit

Permalink
nshlib: Optimize the size of the recursive stack
Browse files Browse the repository at this point in the history
Signed-off-by: Shoukui Zhang <[email protected]>
  • Loading branch information
Zhangshoukui authored and xiaoxiang781216 committed Aug 16, 2024
1 parent 7503f7b commit 7df20ea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions nshlib/nsh_fscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2120,21 +2120,20 @@ int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
#ifdef NSH_HAVE_DIROPTS
#ifndef CONFIG_NSH_DISABLE_RM

static int unlink_recursive(FAR char *path)
static int unlink_recursive(FAR char *path, FAR struct stat *stat)
{
struct dirent *d;
struct stat stat;
size_t len;
int ret;
DIR *dp;

ret = lstat(path, &stat);
ret = lstat(path, stat);
if (ret < 0)
{
return ret;
}

if (!S_ISDIR(stat.st_mode))
if (!S_ISDIR(stat->st_mode))
{
return unlink(path);
}
Expand All @@ -2159,7 +2158,7 @@ static int unlink_recursive(FAR char *path)
}

snprintf(&path[len], PATH_MAX - len, "/%s", d->d_name);
ret = unlink_recursive(path);
ret = unlink_recursive(path, stat);
if (ret < 0)
{
closedir(dp);
Expand All @@ -2182,6 +2181,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
bool recursive = (strcmp(argv[1], "-r") == 0);
FAR char *fullpath;
char buf[PATH_MAX];
struct stat stat;
int ret = ERROR;

if (recursive && argc == 2)
Expand All @@ -2197,7 +2197,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
if (recursive)
{
strlcpy(buf, fullpath, PATH_MAX);
ret = unlink_recursive(buf);
ret = unlink_recursive(buf, &stat);
}
else
{
Expand Down

0 comments on commit 7df20ea

Please sign in to comment.