diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-04-10 17:53:49 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-04-10 17:53:49 +0000 |
commit | fd402941a7612b5254a65edfedc074d66da3883a (patch) | |
tree | 0d5f6f8c802c203543c43b6b4887c8f1130a534b /libbb/recursive_action.c | |
parent | 4e853560f5c4b240be7562530b53851e2c7a246f (diff) | |
download | busybox-w32-fd402941a7612b5254a65edfedc074d66da3883a.tar.gz busybox-w32-fd402941a7612b5254a65edfedc074d66da3883a.tar.bz2 busybox-w32-fd402941a7612b5254a65edfedc074d66da3883a.zip |
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.
Diffstat (limited to 'libbb/recursive_action.c')
-rw-r--r-- | libbb/recursive_action.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index 8424ca0bf..510080b83 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c | |||
@@ -29,8 +29,10 @@ | |||
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <dirent.h> | 30 | #include <dirent.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | #include <stdlib.h> /* free() */ | ||
32 | #include "libbb.h" | 33 | #include "libbb.h" |
33 | 34 | ||
35 | |||
34 | /* same conditions as recursive_action */ | 36 | /* same conditions as recursive_action */ |
35 | #define bb_need_name_too_long | 37 | #define bb_need_name_too_long |
36 | #define BB_DECLARE_EXTERN | 38 | #define BB_DECLARE_EXTERN |
@@ -112,25 +114,18 @@ int recursive_action(const char *fileName, | |||
112 | } | 114 | } |
113 | status = TRUE; | 115 | status = TRUE; |
114 | while ((next = readdir(dir)) != NULL) { | 116 | while ((next = readdir(dir)) != NULL) { |
115 | char nextFile[PATH_MAX]; | 117 | char *nextFile; |
116 | 118 | ||
117 | if ((strcmp(next->d_name, "..") == 0) | 119 | if ((strcmp(next->d_name, "..") == 0) |
118 | || (strcmp(next->d_name, ".") == 0)) { | 120 | || (strcmp(next->d_name, ".") == 0)) { |
119 | continue; | 121 | continue; |
120 | } | 122 | } |
121 | if (strlen(fileName) + strlen(next->d_name) + 1 > PATH_MAX) { | 123 | nextFile = concat_path_file(fileName, next->d_name); |
122 | error_msg(name_too_long); | ||
123 | return FALSE; | ||
124 | } | ||
125 | memset(nextFile, 0, sizeof(nextFile)); | ||
126 | if (fileName[strlen(fileName)-1] == '/') | ||
127 | sprintf(nextFile, "%s%s", fileName, next->d_name); | ||
128 | else | ||
129 | sprintf(nextFile, "%s/%s", fileName, next->d_name); | ||
130 | if (recursive_action(nextFile, TRUE, followLinks, depthFirst, | 124 | if (recursive_action(nextFile, TRUE, followLinks, depthFirst, |
131 | fileAction, dirAction, userData) == FALSE) { | 125 | fileAction, dirAction, userData) == FALSE) { |
132 | status = FALSE; | 126 | status = FALSE; |
133 | } | 127 | } |
128 | free(nextFile); | ||
134 | } | 129 | } |
135 | closedir(dir); | 130 | closedir(dir); |
136 | if (dirAction != NULL && depthFirst == TRUE) { | 131 | if (dirAction != NULL && depthFirst == TRUE) { |