summaryrefslogtreecommitdiff
path: root/deps/uv/src/win/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/win/util.c')
-rw-r--r--deps/uv/src/win/util.c80
1 files changed, 57 insertions, 23 deletions
diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c
index 923789129e..395d958c03 100644
--- a/deps/uv/src/win/util.c
+++ b/deps/uv/src/win/util.c
@@ -59,13 +59,6 @@
# define UNLEN 256
#endif
-/*
- Max hostname length. The Windows gethostname() documentation states that 256
- bytes will always be large enough to hold the null-terminated hostname.
-*/
-#ifndef MAXHOSTNAMELEN
-# define MAXHOSTNAMELEN 256
-#endif
/* Maximum environment variable size, including the terminating null */
#define MAX_ENV_VAR_LENGTH 32767
@@ -684,12 +677,9 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
NULL,
(BYTE*)&cpu_brand,
&cpu_brand_size);
- if (err != ERROR_SUCCESS) {
- RegCloseKey(processor_key);
- goto error;
- }
-
RegCloseKey(processor_key);
+ if (err != ERROR_SUCCESS)
+ goto error;
cpu_info = &cpu_infos[i];
cpu_info->speed = cpu_speed;
@@ -1510,7 +1500,7 @@ int uv_os_unsetenv(const char* name) {
int uv_os_gethostname(char* buffer, size_t* size) {
- char buf[MAXHOSTNAMELEN + 1];
+ char buf[UV_MAXHOSTNAMESIZE];
size_t len;
if (buffer == NULL || size == NULL || *size == 0)
@@ -1634,6 +1624,10 @@ int uv_os_uname(uv_utsname_t* buffer) {
https://github.com/gagern/gnulib/blob/master/lib/uname.c */
OSVERSIONINFOW os_info;
SYSTEM_INFO system_info;
+ HKEY registry_key;
+ WCHAR product_name_w[256];
+ DWORD product_name_w_size;
+ int version_size;
int processor_level;
int r;
@@ -1658,16 +1652,56 @@ int uv_os_uname(uv_utsname_t* buffer) {
}
/* Populate the version field. */
- if (WideCharToMultiByte(CP_UTF8,
- 0,
- os_info.szCSDVersion,
- -1,
- buffer->version,
- sizeof(buffer->version),
- NULL,
- NULL) == 0) {
- r = uv_translate_sys_error(GetLastError());
- goto error;
+ version_size = 0;
+ r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
+ 0,
+ KEY_QUERY_VALUE,
+ &registry_key);
+
+ if (r == ERROR_SUCCESS) {
+ product_name_w_size = sizeof(product_name_w);
+ r = RegGetValueW(registry_key,
+ NULL,
+ L"ProductName",
+ RRF_RT_REG_SZ,
+ NULL,
+ (PVOID) product_name_w,
+ &product_name_w_size);
+ RegCloseKey(registry_key);
+
+ if (r == ERROR_SUCCESS) {
+ version_size = WideCharToMultiByte(CP_UTF8,
+ 0,
+ product_name_w,
+ -1,
+ buffer->version,
+ sizeof(buffer->version),
+ NULL,
+ NULL);
+ if (version_size == 0) {
+ r = uv_translate_sys_error(GetLastError());
+ goto error;
+ }
+ }
+ }
+
+ /* Append service pack information to the version if present. */
+ if (os_info.szCSDVersion[0] != L'\0') {
+ if (version_size > 0)
+ buffer->version[version_size - 1] = ' ';
+
+ if (WideCharToMultiByte(CP_UTF8,
+ 0,
+ os_info.szCSDVersion,
+ -1,
+ buffer->version + version_size,
+ sizeof(buffer->version) - version_size,
+ NULL,
+ NULL) == 0) {
+ r = uv_translate_sys_error(GetLastError());
+ goto error;
+ }
}
/* Populate the sysname field. */