diff options
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r-- | src/nvim/path.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 152154e5f4..72980fcd0e 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -481,6 +481,21 @@ static size_t path_expand(garray_T *gap, const char_u *path, int flags) return do_path_expand(gap, path, 0, flags, false); } +static const char *scandir_next_with_dots(Directory *dir) +{ + static int count = 0; + if (dir == NULL) { // initialize + count = 0; + return NULL; + } + + count += 1; + if (count == 1 || count == 2) { + return (count == 1) ? "." : ".."; + } + return os_scandir_next(dir); +} + /// Implementation of path_expand(). /// /// Chars before `path + wildoff` do not get expanded. @@ -597,11 +612,12 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, *s = NUL; Directory dir; - // open the directory for scanning - if (os_scandir(&dir, *buf == NUL ? "." : (char *)buf)) { + if (os_scandir(&dir, *buf == NUL ? "." : (char *)buf) + || os_isdir(*buf == NUL ? (char_u *)"." : (char_u *)buf)) { // Find all matching entries. char_u *name; - while((name = (char_u *) os_scandir_next(&dir))) { + scandir_next_with_dots(NULL /* initialize */); + while((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) { if ((name[0] != '.' || starts_with_dot) && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) || ((flags & EW_NOTWILD) |