nshlib: Optimize the size of the recursive stack
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
This commit is contained in:
parent
7503f7bf33
commit
7df20ea1bb
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
@ -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)
|
||||
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user