Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ internal FileHandleType GetFileTypeCore()
Debug.Assert(Path is null || _fileOptions != UninitializedOptions, "When Path is set, _fileOptions are also provided.");

int kernelFileType = Interop.Kernel32.GetFileType(this);
// GetFileType returns FILE_TYPE_UNKNOWN both when the type is unknown and when an error occurs.
// Check GetLastError to distinguish the two cases.
if (kernelFileType == Interop.Kernel32.FileTypes.FILE_TYPE_UNKNOWN)
{
int error = Marshal.GetLastPInvokeError();
if (error != Interop.Errors.ERROR_SUCCESS)
Comment thread
jkotas marked this conversation as resolved.
{
throw Win32Marshal.GetExceptionForWin32Error(error, Path);
}
return FileHandleType.Unknown;
Comment thread
jkotas marked this conversation as resolved.
}

return kernelFileType switch
{
Interop.Kernel32.FileTypes.FILE_TYPE_CHAR => FileHandleType.CharacterDevice,
Expand Down
Loading