aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2008-04-24 04:42:52 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2008-04-24 04:42:52 +0000
commitb520271f65d3eb99000db3150dfd8e36c46d7891 (patch)
tree47555d25af653323b477aeedf5a3d3da5e1652f4
parenta50a9b0fdf3d752fc88182bccd47a1eaac79cb4b (diff)
downloadbusybox-b520271f65d3eb99000db3150dfd8e36c46d7891.tar.gz
busybox-b520271f65d3eb99000db3150dfd8e36c46d7891.tar.bz2
lineedit: filename completion on symlinks-to-dirs should add / too
-rw-r--r--libbb/lineedit.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 6de66ba83..5a0d03eeb 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -517,8 +517,8 @@ static void exe_n_cwd_tab_completion(char *command, int type)
for (i = 0; i < npaths; i++) {
dir = opendir(paths[i]);
- if (!dir) /* Don't print an error */
- continue;
+ if (!dir)
+ continue; /* don't print an error */
while ((next = readdir(dir)) != NULL) {
int len1;
@@ -528,18 +528,21 @@ static void exe_n_cwd_tab_completion(char *command, int type)
if (strncmp(str_found, pfind, strlen(pfind)))
continue;
/* not see .name without .match */
- if (*str_found == '.' && *pfind == 0) {
+ if (*str_found == '.' && *pfind == '\0') {
if (NOT_LONE_CHAR(paths[i], '/') || str_found[1])
continue;
str_found = ""; /* only "/" */
}
found = concat_path_file(paths[i], str_found);
- /* hmm, remover in progress? */
- if (lstat(found, &st) < 0)
+ /* hmm, remove in progress? */
+ /* NB: stat() first so that we see is it a directory;
+ * but if that fails, use lstat() so that
+ * we still match dangling links */
+ if (stat(found, &st) && lstat(found, &st))
goto cont;
/* find with dirs? */
if (paths[i] != dirbuf)
- strcpy(found, next->d_name); /* only name */
+ strcpy(found, next->d_name); /* only name */
len1 = strlen(found);
found = xrealloc(found, len1 + 2);
@@ -547,7 +550,7 @@ static void exe_n_cwd_tab_completion(char *command, int type)
found[len1+1] = '\0';
if (S_ISDIR(st.st_mode)) {
- /* name is directory */
+ /* name is a directory */
if (found[len1-1] != '/') {
found[len1] = '/';
}
@@ -565,7 +568,7 @@ static void exe_n_cwd_tab_completion(char *command, int type)
closedir(dir);
}
if (paths != path1) {
- free(paths[0]); /* allocated memory only in first member */
+ free(paths[0]); /* allocated memory is only in first member */
free(paths);
}
#undef dirbuf