summaryrefslogtreecommitdiff
path: root/src/win32/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/win32/dir.c')
-rw-r--r--src/win32/dir.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/win32/dir.c b/src/win32/dir.c
index 0a634f06f..23bc55558 100644
--- a/src/win32/dir.c
+++ b/src/win32/dir.c
@@ -58,25 +58,37 @@ git__DIR *git__opendir(const char *dir)
return new;
}
-struct git__dirent *git__readdir(git__DIR *d)
+int git__readdir_r(
+ git__DIR *d, struct git__dirent *entry, struct git__dirent **result)
{
- if (!d || d->h == INVALID_HANDLE_VALUE)
- return NULL;
+ if (!d || !entry || !result || d->h == INVALID_HANDLE_VALUE)
+ return -1;
if (d->first)
d->first = 0;
- else {
- if (!FindNextFileW(d->h, &d->f))
- return NULL;
+ else if (!FindNextFileW(d->h, &d->f)) {
+ *result = NULL;
+ return 0;
}
- if (wcslen(d->f.cFileName) >= sizeof(d->entry.d_name))
- return NULL;
+ if (wcslen(d->f.cFileName) >= sizeof(entry->d_name))
+ return -1;
+
+ entry->d_ino = 0;
+ WideCharToMultiByte(
+ gitwin_get_codepage(), 0, d->f.cFileName, -1,
+ entry->d_name, GIT_PATH_MAX, NULL, NULL);
- d->entry.d_ino = 0;
- WideCharToMultiByte(gitwin_get_codepage(), 0, d->f.cFileName, -1, d->entry.d_name, GIT_PATH_MAX, NULL, NULL);
+ *result = entry;
+ return 0;
+}
- return &d->entry;
+struct git__dirent *git__readdir(git__DIR *d)
+{
+ struct git__dirent *result;
+ if (git__readdir_r(d, &d->entry, &result) < 0)
+ return NULL;
+ return result;
}
void git__rewinddir(git__DIR *d)