summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/win/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmlibuv/src/win/util.c')
-rw-r--r--Utilities/cmlibuv/src/win/util.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Utilities/cmlibuv/src/win/util.c b/Utilities/cmlibuv/src/win/util.c
index aad8f1a..33e874a 100644
--- a/Utilities/cmlibuv/src/win/util.c
+++ b/Utilities/cmlibuv/src/win/util.c
@@ -1664,26 +1664,36 @@ int uv_os_unsetenv(const char* name) {
int uv_os_gethostname(char* buffer, size_t* size) {
- char buf[UV_MAXHOSTNAMESIZE];
+ WCHAR buf[UV_MAXHOSTNAMESIZE];
size_t len;
+ char* utf8_str;
+ int convert_result;
if (buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
uv__once_init(); /* Initialize winsock */
- if (gethostname(buf, sizeof(buf)) != 0)
+ if (pGetHostNameW == NULL)
+ return UV_ENOSYS;
+
+ if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) != 0)
return uv_translate_sys_error(WSAGetLastError());
- buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */
- len = strlen(buf);
+ convert_result = uv__convert_utf16_to_utf8(buf, -1, &utf8_str);
+
+ if (convert_result != 0)
+ return convert_result;
+ len = strlen(utf8_str);
if (len >= *size) {
*size = len + 1;
+ uv__free(utf8_str);
return UV_ENOBUFS;
}
- memcpy(buffer, buf, len + 1);
+ memcpy(buffer, utf8_str, len + 1);
+ uv__free(utf8_str);
*size = len;
return 0;
}