Skip to content

Commit

Permalink
win: return product name in uv_os_uname() version
Browse files Browse the repository at this point in the history
Currently, on Windows the uv_utsname_t's version field can
be an empty string if no service packs are installed. This isn't
very helpful, and a lot more information is available in the
Windows registry. This commit prepends the full product name
to the existing service pack information.

Refs: nodejs/node#25843
Refs: libuv#2128 (comment)
  • Loading branch information
cjihrig committed Feb 2, 2019
1 parent a9e6cc7 commit a5c7870
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions src/win/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,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;

Expand All @@ -1658,18 +1662,58 @@ 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 = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE,
&registry_key);
if (r != ERROR_SUCCESS) {
r = uv_translate_sys_error(r);
goto error;
}

product_name_w_size = sizeof(product_name_w);
r = RegQueryValueExW(registry_key,
L"ProductName",
NULL,
NULL,
(BYTE*) &product_name_w,
&product_name_w_size);
RegCloseKey(registry_key);
if (r != ERROR_SUCCESS) {
r = uv_translate_sys_error(r);
goto error;
}

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') {
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. */
#ifdef __MINGW32__
r = snprintf(buffer->sysname,
Expand Down

0 comments on commit a5c7870

Please sign in to comment.