Skip to content

Commit 7df20ea

Browse files
Zhangshoukuixiaoxiang781216
authored andcommitted
nshlib: Optimize the size of the recursive stack
Signed-off-by: Shoukui Zhang <[email protected]>
1 parent 7503f7b commit 7df20ea

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

nshlib/nsh_fscmds.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,21 +2120,20 @@ int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
21202120
#ifdef NSH_HAVE_DIROPTS
21212121
#ifndef CONFIG_NSH_DISABLE_RM
21222122

2123-
static int unlink_recursive(FAR char *path)
2123+
static int unlink_recursive(FAR char *path, FAR struct stat *stat)
21242124
{
21252125
struct dirent *d;
2126-
struct stat stat;
21272126
size_t len;
21282127
int ret;
21292128
DIR *dp;
21302129

2131-
ret = lstat(path, &stat);
2130+
ret = lstat(path, stat);
21322131
if (ret < 0)
21332132
{
21342133
return ret;
21352134
}
21362135

2137-
if (!S_ISDIR(stat.st_mode))
2136+
if (!S_ISDIR(stat->st_mode))
21382137
{
21392138
return unlink(path);
21402139
}
@@ -2159,7 +2158,7 @@ static int unlink_recursive(FAR char *path)
21592158
}
21602159

21612160
snprintf(&path[len], PATH_MAX - len, "/%s", d->d_name);
2162-
ret = unlink_recursive(path);
2161+
ret = unlink_recursive(path, stat);
21632162
if (ret < 0)
21642163
{
21652164
closedir(dp);
@@ -2182,6 +2181,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
21822181
bool recursive = (strcmp(argv[1], "-r") == 0);
21832182
FAR char *fullpath;
21842183
char buf[PATH_MAX];
2184+
struct stat stat;
21852185
int ret = ERROR;
21862186

21872187
if (recursive && argc == 2)
@@ -2197,7 +2197,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
21972197
if (recursive)
21982198
{
21992199
strlcpy(buf, fullpath, PATH_MAX);
2200-
ret = unlink_recursive(buf);
2200+
ret = unlink_recursive(buf, &stat);
22012201
}
22022202
else
22032203
{

0 commit comments

Comments
 (0)