|
static_assert(sizeof(uintmax_t) == sizeof(ULARGE_INTEGER) && alignof(uintmax_t) == alignof(ULARGE_INTEGER), |
|
"Size and alignment must match for reinterpret_cast<PULARGE_INTEGER>"); |
|
|
|
[[nodiscard]] __std_win_error _Fs_space_attempt(wchar_t* const _Temp_buffer, const DWORD _Temp_buffer_characters, |
|
const wchar_t* const _Target, uintmax_t* const _Available, uintmax_t* const _Total_bytes, |
|
uintmax_t* const _Free_bytes) noexcept { |
|
if (GetVolumePathNameW(_Target, _Temp_buffer, _Temp_buffer_characters)) { |
|
if (GetDiskFreeSpaceExW(_Temp_buffer, reinterpret_cast<PULARGE_INTEGER>(_Available), |
|
reinterpret_cast<PULARGE_INTEGER>(_Total_bytes), reinterpret_cast<PULARGE_INTEGER>(_Free_bytes))) { |
|
return __std_win_error::_Success; |
|
} |
|
} |
|
|
|
return __std_win_error{GetLastError()}; |
|
} |
In #356 (comment), Charles Milette (@sylveon) asked whether this static_assert and reinterpret_cast technique is necessary. I believe that we could avoid this by defining ULARGE_INTEGER local variables, passing their addresses to GetDiskFreeSpaceExW(), and then if successful, writing their QuadParts to _Available, _Total_bytes, and _Free_bytes. This would involve a few more instructions, but I don't believe that the code size and runtime impact would be observable, and avoiding reinterpret_cast may be worth it.
STL/stl/src/filesystem_space.cpp
Lines 19 to 33 in da0d8cf
In #356 (comment), Charles Milette (@sylveon) asked whether this
static_assertandreinterpret_casttechnique is necessary. I believe that we could avoid this by definingULARGE_INTEGERlocal variables, passing their addresses toGetDiskFreeSpaceExW(), and then if successful, writing theirQuadParts to_Available,_Total_bytes, and_Free_bytes. This would involve a few more instructions, but I don't believe that the code size and runtime impact would be observable, and avoidingreinterpret_castmay be worth it.