summaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c198
1 files changed, 101 insertions, 97 deletions
diff --git a/src/fileio.c b/src/fileio.c
index e80009fbe..6e66a3e86 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3367,6 +3367,7 @@ shorten_fnames(int force)
#if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \
|| defined(FEAT_GUI_MSWIN) \
|| defined(FEAT_GUI_MAC) \
+ || defined(FEAT_GUI_HAIKU) \
|| defined(PROTO)
/*
* Shorten all filenames in "fnames[count]" by current directory.
@@ -4422,130 +4423,133 @@ readdir_core(
void *context,
int (*checkitem)(void *context, char_u *name))
{
- int failed = FALSE;
-# ifdef MSWIN
- char_u *buf, *p;
- int ok;
- HANDLE hFind = INVALID_HANDLE_VALUE;
- WIN32_FIND_DATAW wfb;
- WCHAR *wn = NULL; // UTF-16 name, NULL when not used.
-# endif
+ int failed = FALSE;
+ char_u *p;
ga_init2(gap, (int)sizeof(char *), 20);
# ifdef MSWIN
- buf = alloc(MAXPATHL);
- if (buf == NULL)
- return FAIL;
- STRNCPY(buf, path, MAXPATHL-5);
- p = buf + STRLEN(buf);
- MB_PTR_BACK(buf, p);
- if (*p == '\\' || *p == '/')
- *p = NUL;
- STRCAT(buf, "\\*");
-
- wn = enc_to_utf16(buf, NULL);
- if (wn != NULL)
- hFind = FindFirstFileW(wn, &wfb);
- ok = (hFind != INVALID_HANDLE_VALUE);
- if (!ok)
{
- failed = TRUE;
- smsg(_(e_notopen), path);
- }
- else
- {
- while (ok)
+ char_u *buf;
+ int ok;
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATAW wfb;
+ WCHAR *wn = NULL; // UTF-16 name, NULL when not used.
+
+ buf = alloc(MAXPATHL);
+ if (buf == NULL)
+ return FAIL;
+ STRNCPY(buf, path, MAXPATHL-5);
+ p = buf + STRLEN(buf);
+ MB_PTR_BACK(buf, p);
+ if (*p == '\\' || *p == '/')
+ *p = NUL;
+ STRCAT(buf, "\\*");
+
+ wn = enc_to_utf16(buf, NULL);
+ if (wn != NULL)
+ hFind = FindFirstFileW(wn, &wfb);
+ ok = (hFind != INVALID_HANDLE_VALUE);
+ if (!ok)
{
- int ignore;
-
- p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here
- if (p == NULL)
- break; // out of memory
-
- ignore = p[0] == '.' && (p[1] == NUL
- || (p[1] == '.' && p[2] == NUL));
- if (!ignore && checkitem != NULL)
+ failed = TRUE;
+ smsg(_(e_notopen), path);
+ }
+ else
+ {
+ while (ok)
{
- int r = checkitem(context, p);
+ int ignore;
+
+ p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here
+ if (p == NULL)
+ break; // out of memory
- if (r < 0)
+ ignore = p[0] == '.' && (p[1] == NUL
+ || (p[1] == '.' && p[2] == NUL));
+ if (!ignore && checkitem != NULL)
{
- vim_free(p);
- break;
+ int r = checkitem(context, p);
+
+ if (r < 0)
+ {
+ vim_free(p);
+ break;
+ }
+ if (r == 0)
+ ignore = TRUE;
}
- if (r == 0)
- ignore = TRUE;
- }
- if (!ignore)
- {
- if (ga_grow(gap, 1) == OK)
- ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p);
- else
+ if (!ignore)
{
- failed = TRUE;
- vim_free(p);
- break;
+ if (ga_grow(gap, 1) == OK)
+ ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p);
+ else
+ {
+ failed = TRUE;
+ vim_free(p);
+ break;
+ }
}
- }
- vim_free(p);
- ok = FindNextFileW(hFind, &wfb);
+ vim_free(p);
+ ok = FindNextFileW(hFind, &wfb);
+ }
+ FindClose(hFind);
}
- FindClose(hFind);
- }
-
- vim_free(buf);
- vim_free(wn);
-# else
- DIR *dirp;
- struct dirent *dp;
- char_u *p;
- dirp = opendir((char *)path);
- if (dirp == NULL)
- {
- failed = TRUE;
- smsg(_(e_notopen), path);
+ vim_free(buf);
+ vim_free(wn);
}
- else
+# else
{
- for (;;)
- {
- int ignore;
-
- dp = readdir(dirp);
- if (dp == NULL)
- break;
- p = (char_u *)dp->d_name;
+ DIR *dirp;
+ struct dirent *dp;
- ignore = p[0] == '.' &&
- (p[1] == NUL ||
- (p[1] == '.' && p[2] == NUL));
- if (!ignore && checkitem != NULL)
+ dirp = opendir((char *)path);
+ if (dirp == NULL)
+ {
+ failed = TRUE;
+ smsg(_(e_notopen), path);
+ }
+ else
+ {
+ for (;;)
{
- int r = checkitem(context, p);
+ int ignore;
- if (r < 0)
+ dp = readdir(dirp);
+ if (dp == NULL)
break;
- if (r == 0)
- ignore = TRUE;
- }
+ p = (char_u *)dp->d_name;
- if (!ignore)
- {
- if (ga_grow(gap, 1) == OK)
- ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p);
- else
+ ignore = p[0] == '.' &&
+ (p[1] == NUL ||
+ (p[1] == '.' && p[2] == NUL));
+ if (!ignore && checkitem != NULL)
{
- failed = TRUE;
- break;
+ int r = checkitem(context, p);
+
+ if (r < 0)
+ break;
+ if (r == 0)
+ ignore = TRUE;
+ }
+
+ if (!ignore)
+ {
+ if (ga_grow(gap, 1) == OK)
+ ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p);
+ else
+ {
+ failed = TRUE;
+ break;
+ }
}
}
- }
- closedir(dirp);
+ closedir(dirp);
+ }
}
# endif