38 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include <__config>10#include <cstdio>11#include <fstream>12 13#if defined(_LIBCPP_WIN32API)14# define WIN32_LEAN_AND_MEAN15# define NOMINMAX16# include <io.h>17# include <windows.h>18#endif19 20_LIBCPP_BEGIN_NAMESPACE_STD21 22#if defined(_LIBCPP_WIN32API)23 24// Confirm that `HANDLE` is `void*` as implemented in `basic_filebuf`25static_assert(std::same_as<HANDLE, void*>);26 27_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept {28 // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-17029 intptr_t __handle = _get_osfhandle(fileno(__file));30 if (__handle == -1)31 return nullptr;32 return reinterpret_cast<void*>(__handle);33}34 35#endif36 37_LIBCPP_END_NAMESPACE_STD38