aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-08-01 23:16:17 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-08-01 23:16:53 -0400
commitdd7c7efcfb37342ccd9168977b2431d16de7b3cb (patch)
tree22fb3ae8dd192f9dc50053b02d33e76af73a6af1 /src/nvim/path.c
parentd4396acedb213209aee4693e196f1952bbc88ff5 (diff)
parentea551044ea8a0de8e2f6937c9d083cecd2f67b99 (diff)
downloadrneovim-dd7c7efcfb37342ccd9168977b2431d16de7b3cb.tar.gz
rneovim-dd7c7efcfb37342ccd9168977b2431d16de7b3cb.tar.bz2
rneovim-dd7c7efcfb37342ccd9168977b2431d16de7b3cb.zip
Merge #3099 glob() should return '.' and '..'
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 152154e5f4..9d9cd933b4 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -481,6 +481,28 @@ 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;
+ const char *entry = NULL;
+ if (dir == NULL) {
+ count = 0;
+ } else {
+ count += 1;
+ if (count == 1) {
+ entry = ".";
+ } else if (count == 2) {
+ entry = "..";
+ } else {
+ entry = os_scandir_next(dir);
+ if (entry == NULL) {
+ count = 0;
+ }
+ }
+ }
+ return entry;
+}
+
/// Implementation of path_expand().
///
/// Chars before `path + wildoff` do not get expanded.
@@ -597,11 +619,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);
+ while((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) {
if ((name[0] != '.' || starts_with_dot)
&& ((regmatch.regprog != NULL && vim_regexec(&regmatch, name, 0))
|| ((flags & EW_NOTWILD)