in include/wil/filesystem.h [885:924]
inline HRESULT GetFileInfo(HANDLE fileHandle, FILE_INFO_BY_HANDLE_CLASS infoClass, size_t allocationSize,
_Outptr_result_nullonfailure_ void **result)
{
*result = nullptr;
wistd::unique_ptr<char[]> resultHolder(new(std::nothrow) char[allocationSize]);
RETURN_IF_NULL_ALLOC(resultHolder);
for (;;)
{
if (GetFileInformationByHandleEx(fileHandle, infoClass, resultHolder.get(), static_cast<DWORD>(allocationSize)))
{
*result = resultHolder.release();
break;
}
else
{
DWORD const lastError = ::GetLastError();
if (lastError == ERROR_MORE_DATA)
{
allocationSize *= 2;
resultHolder.reset(new(std::nothrow) char[allocationSize]);
RETURN_IF_NULL_ALLOC(resultHolder);
}
else if (lastError == ERROR_NO_MORE_FILES) // for folder enumeration cases
{
break;
}
else if (lastError == ERROR_INVALID_PARAMETER) // operation not supported by file system
{
return HRESULT_FROM_WIN32(lastError);
}
else
{
RETURN_WIN32(lastError);
}
}
}
return S_OK;
}