[libcxx-commits] [libcxx] [libc++] Optimize std::print for Windows 8+ (PR #232993)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 22 23:47:16 PDT 2026
================
@@ -37,18 +40,52 @@ _LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
#ifdef _WIN32
-_LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream) {
+using NtQueryVolumeInformationFileType = NTSTATUS
+ NTAPI(HANDLE handle, PIO_STATUS_BLOCK ioStatus, PVOID information, ULONG length, ULONG informationClass);
+
+// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_file_fs_device_information
+struct FILE_FS_DEVICE_INFORMATION {
+ DEVICE_TYPE DeviceType;
+ ULONG Characteristics;
+};
+
+// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ne-wdm-_fsinfoclass
+# define FileFsDeviceInformation 4
+
+static NtQueryVolumeInformationFileType* __get_NtQVIF_win8_or_greater() {
+ // Windows 7 does not support querying the device type of a console handle, so returning nullptr indicates that this
+ // approach is not supported.
+ if (!IsWindows8OrGreater())
+ return nullptr;
+ return (NtQueryVolumeInformationFileType*)GetProcAddress(
----------------
mstorsjo wrote:
IIRC it's not strictly well defined what happens if you pass `NULL` to `GetProcAddress` (if `GetModuleHandleW` fails). In practice it's fine, but if possible it's nicer if we can check the return value of `GetModuleHandleW` before, too.
https://github.com/llvm/llvm-project/pull/232993
More information about the libcxx-commits
mailing list