[libcxx-commits] [libcxx] [libc++] Optimize std::print for Windows 8+ (PR #232993)
Yexuan Xiao via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 23 01:37:23 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(
----------------
YexuanXiao wrote:
[chrono.cpp](https://github.com/llvm/llvm-project/blob/97d6feca9de0c1fdbbb346aaa8d0ff5cdc4d6b06/libcxx/src/chrono.cpp#L85-L86) uses a similar approach, so I think it's fine?
https://github.com/llvm/llvm-project/pull/232993
More information about the libcxx-commits
mailing list