Skip to content

Commit 3908af5

Browse files
committed
win: return product name in uv_os_uname() version
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) PR-URL: libuv#2170 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]>
1 parent 8865e72 commit 3908af5

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

src/win/util.c

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,10 @@ int uv_os_uname(uv_utsname_t* buffer) {
16241624
https://github.com/gagern/gnulib/blob/master/lib/uname.c */
16251625
OSVERSIONINFOW os_info;
16261626
SYSTEM_INFO system_info;
1627+
HKEY registry_key;
1628+
WCHAR product_name_w[256];
1629+
DWORD product_name_w_size;
1630+
int version_size;
16271631
int processor_level;
16281632
int r;
16291633

@@ -1648,16 +1652,56 @@ int uv_os_uname(uv_utsname_t* buffer) {
16481652
}
16491653

16501654
/* Populate the version field. */
1651-
if (WideCharToMultiByte(CP_UTF8,
1652-
0,
1653-
os_info.szCSDVersion,
1654-
-1,
1655-
buffer->version,
1656-
sizeof(buffer->version),
1657-
NULL,
1658-
NULL) == 0) {
1659-
r = uv_translate_sys_error(GetLastError());
1660-
goto error;
1655+
version_size = 0;
1656+
r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1657+
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
1658+
0,
1659+
KEY_QUERY_VALUE,
1660+
&registry_key);
1661+
1662+
if (r == ERROR_SUCCESS) {
1663+
product_name_w_size = sizeof(product_name_w);
1664+
r = RegGetValueW(registry_key,
1665+
NULL,
1666+
L"ProductName",
1667+
RRF_RT_REG_SZ,
1668+
NULL,
1669+
(PVOID) product_name_w,
1670+
&product_name_w_size);
1671+
RegCloseKey(registry_key);
1672+
1673+
if (r == ERROR_SUCCESS) {
1674+
version_size = WideCharToMultiByte(CP_UTF8,
1675+
0,
1676+
product_name_w,
1677+
-1,
1678+
buffer->version,
1679+
sizeof(buffer->version),
1680+
NULL,
1681+
NULL);
1682+
if (version_size == 0) {
1683+
r = uv_translate_sys_error(GetLastError());
1684+
goto error;
1685+
}
1686+
}
1687+
}
1688+
1689+
/* Append service pack information to the version if present. */
1690+
if (os_info.szCSDVersion[0] != L'\0') {
1691+
if (version_size > 0)
1692+
buffer->version[version_size - 1] = ' ';
1693+
1694+
if (WideCharToMultiByte(CP_UTF8,
1695+
0,
1696+
os_info.szCSDVersion,
1697+
-1,
1698+
buffer->version + version_size,
1699+
sizeof(buffer->version) - version_size,
1700+
NULL,
1701+
NULL) == 0) {
1702+
r = uv_translate_sys_error(GetLastError());
1703+
goto error;
1704+
}
16611705
}
16621706

16631707
/* Populate the sysname field. */

0 commit comments

Comments
 (0)