Patch from Valdimir to reduce stack usage, since recursive_action
is (as the name implies) is recursive, reducing stack memory usage is important to avoid exhausting available stack memory.
This commit is contained in:
@ -29,8 +29,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <stdlib.h> /* free() */
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
|
||||||
/* same conditions as recursive_action */
|
/* same conditions as recursive_action */
|
||||||
#define bb_need_name_too_long
|
#define bb_need_name_too_long
|
||||||
#define BB_DECLARE_EXTERN
|
#define BB_DECLARE_EXTERN
|
||||||
@ -112,25 +114,18 @@ int recursive_action(const char *fileName,
|
|||||||
}
|
}
|
||||||
status = TRUE;
|
status = TRUE;
|
||||||
while ((next = readdir(dir)) != NULL) {
|
while ((next = readdir(dir)) != NULL) {
|
||||||
char nextFile[PATH_MAX];
|
char *nextFile;
|
||||||
|
|
||||||
if ((strcmp(next->d_name, "..") == 0)
|
if ((strcmp(next->d_name, "..") == 0)
|
||||||
|| (strcmp(next->d_name, ".") == 0)) {
|
|| (strcmp(next->d_name, ".") == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strlen(fileName) + strlen(next->d_name) + 1 > PATH_MAX) {
|
nextFile = concat_path_file(fileName, next->d_name);
|
||||||
error_msg(name_too_long);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
memset(nextFile, 0, sizeof(nextFile));
|
|
||||||
if (fileName[strlen(fileName)-1] == '/')
|
|
||||||
sprintf(nextFile, "%s%s", fileName, next->d_name);
|
|
||||||
else
|
|
||||||
sprintf(nextFile, "%s/%s", fileName, next->d_name);
|
|
||||||
if (recursive_action(nextFile, TRUE, followLinks, depthFirst,
|
if (recursive_action(nextFile, TRUE, followLinks, depthFirst,
|
||||||
fileAction, dirAction, userData) == FALSE) {
|
fileAction, dirAction, userData) == FALSE) {
|
||||||
status = FALSE;
|
status = FALSE;
|
||||||
}
|
}
|
||||||
|
free(nextFile);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
if (dirAction != NULL && depthFirst == TRUE) {
|
if (dirAction != NULL && depthFirst == TRUE) {
|
||||||
|
Reference in New Issue
Block a user