diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-26 03:26:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-26 03:26:57 +0000 |
commit | 2649f215aecf923713d2f9a379cf651437ddf499 (patch) | |
tree | 267293cd8ebdc2ab8ec6a0663d9a59b4986d6800 /libbb/recursive_action.c | |
parent | a04cc47f1c53c34e81a7271d687d8b68d0489892 (diff) | |
download | busybox-w32-2649f215aecf923713d2f9a379cf651437ddf499.tar.gz busybox-w32-2649f215aecf923713d2f9a379cf651437ddf499.tar.bz2 busybox-w32-2649f215aecf923713d2f9a379cf651437ddf499.zip |
open_transformer: fix bug of calling exit instead of _exit
open_transformer: don't leak compressed descriptor anymore
recursive_action: tiny shrink
Diffstat (limited to 'libbb/recursive_action.c')
-rw-r--r-- | libbb/recursive_action.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index 513aff315..fe9ba2ecc 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c | |||
@@ -34,9 +34,19 @@ static int true_action(const char *fileName ATTRIBUTE_UNUSED, | |||
34 | * recursive_action() return 0, but it doesn't stop directory traversal | 34 | * recursive_action() return 0, but it doesn't stop directory traversal |
35 | * (fileAction/dirAction will be called on each file). | 35 | * (fileAction/dirAction will be called on each file). |
36 | * | 36 | * |
37 | * if !depthFirst, dirAction return value of 0 (FALSE) or 2 (SKIP) | 37 | * If !ACTION_RECURSE, dirAction is called on the directory and its |
38 | * prevents recursion into that directory, instead | 38 | * return value is returned from recursive_action(). No recursion. |
39 | * recursive_action() returns 0 (if FALSE) or 1 (if SKIP). | 39 | * |
40 | * If ACTION_RECURSE, recursive_action() is called on each directory. | ||
41 | * If any one of these calls returns 0, current recursive_action() returns 0. | ||
42 | * | ||
43 | * If ACTION_DEPTHFIRST, dirAction is called after recurse. | ||
44 | * If it returns 0, the warning is printed and recursive_action() returns 0. | ||
45 | * | ||
46 | * If !ACTION_DEPTHFIRST, dirAction is called before we recurse. | ||
47 | * Return value of 0 (FALSE) or 2 (SKIP) prevents recursion | ||
48 | * into that directory, instead recursive_action() returns 0 (if FALSE) | ||
49 | * or 1 (if SKIP) | ||
40 | * | 50 | * |
41 | * followLinks=0/1 differs mainly in handling of links to dirs. | 51 | * followLinks=0/1 differs mainly in handling of links to dirs. |
42 | * 0: lstat(statbuf). Calls fileAction on link name even if points to dir. | 52 | * 0: lstat(statbuf). Calls fileAction on link name even if points to dir. |
@@ -59,7 +69,8 @@ int recursive_action(const char *fileName, | |||
59 | if (!dirAction) dirAction = true_action; | 69 | if (!dirAction) dirAction = true_action; |
60 | 70 | ||
61 | status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */ | 71 | status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */ |
62 | if (!depth) status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; | 72 | if (!depth) |
73 | status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; | ||
63 | status = ((flags & status) ? stat : lstat)(fileName, &statbuf); | 74 | status = ((flags & status) ? stat : lstat)(fileName, &statbuf); |
64 | if (status < 0) { | 75 | if (status < 0) { |
65 | #ifdef DEBUG_RECURS_ACTION | 76 | #ifdef DEBUG_RECURS_ACTION |
@@ -105,8 +116,9 @@ int recursive_action(const char *fileName, | |||
105 | nextFile = concat_subpath_file(fileName, next->d_name); | 116 | nextFile = concat_subpath_file(fileName, next->d_name); |
106 | if (nextFile == NULL) | 117 | if (nextFile == NULL) |
107 | continue; | 118 | continue; |
108 | /* now descend into it (NB: ACTION_RECURSE is set in flags) */ | 119 | /* process every file (NB: ACTION_RECURSE is set in flags) */ |
109 | if (!recursive_action(nextFile, flags, fileAction, dirAction, userData, depth+1)) | 120 | if (!recursive_action(nextFile, flags, fileAction, dirAction, |
121 | userData, depth + 1)) | ||
110 | status = FALSE; | 122 | status = FALSE; |
111 | free(nextFile); | 123 | free(nextFile); |
112 | } | 124 | } |
@@ -117,9 +129,7 @@ int recursive_action(const char *fileName, | |||
117 | goto done_nak_warn; | 129 | goto done_nak_warn; |
118 | } | 130 | } |
119 | 131 | ||
120 | if (!status) | 132 | return status; |
121 | return FALSE; | ||
122 | return TRUE; | ||
123 | 133 | ||
124 | done_nak_warn: | 134 | done_nak_warn: |
125 | bb_simple_perror_msg(fileName); | 135 | bb_simple_perror_msg(fileName); |