mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 13:04:42 +00:00
Fix opendir/readdir and friends on Win32 to use Unicode
This commit is contained in:
parent
7998ae5ab1
commit
6d0ef97478
@ -22,7 +22,7 @@ struct git__dirent {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
WIN32_FIND_DATA f;
|
WIN32_FIND_DATAW f;
|
||||||
struct git__dirent entry;
|
struct git__dirent entry;
|
||||||
char *dir;
|
char *dir;
|
||||||
int first;
|
int first;
|
||||||
|
@ -26,6 +26,7 @@ static int init_filter(char *filter, size_t n, const char *dir)
|
|||||||
git__DIR *git__opendir(const char *dir)
|
git__DIR *git__opendir(const char *dir)
|
||||||
{
|
{
|
||||||
char filter[4096];
|
char filter[4096];
|
||||||
|
wchar_t* filter_w;
|
||||||
git__DIR *new;
|
git__DIR *new;
|
||||||
|
|
||||||
if (!dir || !init_filter(filter, sizeof(filter), dir))
|
if (!dir || !init_filter(filter, sizeof(filter), dir))
|
||||||
@ -42,7 +43,10 @@ git__DIR *git__opendir(const char *dir)
|
|||||||
}
|
}
|
||||||
strcpy(new->dir, dir);
|
strcpy(new->dir, dir);
|
||||||
|
|
||||||
new->h = FindFirstFile(filter, &new->f);
|
filter_w = conv_utf8_to_utf16(filter);
|
||||||
|
new->h = FindFirstFileW(filter_w, &new->f);
|
||||||
|
free(filter_w);
|
||||||
|
|
||||||
if (new->h == INVALID_HANDLE_VALUE) {
|
if (new->h == INVALID_HANDLE_VALUE) {
|
||||||
free(new->dir);
|
free(new->dir);
|
||||||
free(new);
|
free(new);
|
||||||
@ -61,15 +65,15 @@ struct git__dirent *git__readdir(git__DIR *d)
|
|||||||
if (d->first)
|
if (d->first)
|
||||||
d->first = 0;
|
d->first = 0;
|
||||||
else {
|
else {
|
||||||
if (!FindNextFile(d->h, &d->f))
|
if (!FindNextFileW(d->h, &d->f))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(d->f.cFileName) >= sizeof(d->entry.d_name))
|
if (wcslen(d->f.cFileName) >= sizeof(d->entry.d_name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
d->entry.d_ino = 0;
|
d->entry.d_ino = 0;
|
||||||
strcpy(d->entry.d_name, d->f.cFileName);
|
WideCharToMultiByte(CP_UTF8, 0, d->f.cFileName, -1, d->entry.d_name, GIT_PATH_MAX, NULL, NULL);
|
||||||
|
|
||||||
return &d->entry;
|
return &d->entry;
|
||||||
}
|
}
|
||||||
@ -77,14 +81,19 @@ struct git__dirent *git__readdir(git__DIR *d)
|
|||||||
void git__rewinddir(git__DIR *d)
|
void git__rewinddir(git__DIR *d)
|
||||||
{
|
{
|
||||||
char filter[4096];
|
char filter[4096];
|
||||||
|
wchar_t* filter_w;
|
||||||
|
|
||||||
if (d) {
|
if (d) {
|
||||||
if (d->h != INVALID_HANDLE_VALUE)
|
if (d->h != INVALID_HANDLE_VALUE)
|
||||||
FindClose(d->h);
|
FindClose(d->h);
|
||||||
d->h = INVALID_HANDLE_VALUE;
|
d->h = INVALID_HANDLE_VALUE;
|
||||||
d->first = 0;
|
d->first = 0;
|
||||||
|
|
||||||
if (init_filter(filter, sizeof(filter), d->dir)) {
|
if (init_filter(filter, sizeof(filter), d->dir)) {
|
||||||
d->h = FindFirstFile(filter, &d->f);
|
filter_w = conv_utf8_to_utf16(filter);
|
||||||
|
d->h = FindFirstFileW(filter_w, &d->f);
|
||||||
|
free(filter_w);
|
||||||
|
|
||||||
if (d->h != INVALID_HANDLE_VALUE)
|
if (d->h != INVALID_HANDLE_VALUE)
|
||||||
d->first = 1;
|
d->first = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user