Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

windows: fix utf16->utf8 conversion in uv_fs_readdir

  • Loading branch information...
Igor Zinkovsky
Igor Zinkovsky committed Nov 9, 2011
1 parent 196e145 commit 942c68b80ed85bf1c360803a446bf0cc8cd16de0
Showing with 7 additions and 7 deletions.
  1. +7 −7 src/win/fs.c
@@ -388,7 +388,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {
HANDLE dir;
WIN32_FIND_DATAW ent = {0};
size_t len = wcslen(path);
size_t buf_size = 4096;
size_t buf_char_len = 4096;
wchar_t* path2;
const wchar_t* fmt = !len ? L"./*"
: (path[len - 1] == L'/' || path[len - 1] == L'\\') ? L"%s*"
@@ -429,18 +429,18 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {
len = wcslen(name);

if (!buf) {
buf = (wchar_t*)malloc(buf_size * sizeof(wchar_t));
buf = (wchar_t*)malloc(buf_char_len * sizeof(wchar_t));
if (!buf) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

ptr = buf;
}

while ((ptr - buf) + len + 1 > buf_size) {
buf_size *= 2;
while ((ptr - buf) + len + 1 > buf_char_len) {
buf_char_len *= 2;
path2 = buf;
buf = (wchar_t*)realloc(buf, buf_size * sizeof(wchar_t));
buf = (wchar_t*)realloc(buf, buf_char_len * sizeof(wchar_t));
if (!buf) {
uv_fatal_error(ERROR_OUTOFMEMORY, "realloc");
}
@@ -458,7 +458,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {

if (buf) {
/* Convert result to UTF8. */
size = uv_utf16_to_utf8(buf, buf_size / sizeof(wchar_t), NULL, 0);
size = uv_utf16_to_utf8(buf, buf_char_len, NULL, 0);
if (!size) {
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
@@ -469,7 +469,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

size = uv_utf16_to_utf8(buf, buf_size / sizeof(wchar_t), (char*)req->ptr, size);
size = uv_utf16_to_utf8(buf, buf_char_len, (char*)req->ptr, size);
if (!size) {
free(buf);
free(req->ptr);

0 comments on commit 942c68b

Please sign in to comment.
You can’t perform that action at this time.