Implemented GetFileType()

Some cleanup

svn path=/trunk/; revision=1374
This commit is contained in:
Eric Kohl 2000-10-01 19:54:57 +00:00
parent 31f697ce8f
commit f3632d15b8

View file

@ -1,4 +1,4 @@
/* $Id: file.c,v 1.23 2000/06/03 14:47:32 ea Exp $ /* $Id: file.c,v 1.24 2000/10/01 19:54:57 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -229,6 +229,71 @@ DWORD STDCALL SetFilePointer(HANDLE hFile,
DWORD STDCALL GetFileType(HANDLE hFile) DWORD STDCALL GetFileType(HANDLE hFile)
{ {
FILE_FS_DEVICE_INFORMATION DeviceInfo;
IO_STATUS_BLOCK StatusBlock;
NTSTATUS Status;
/* get real handle */
switch ((ULONG)hFile)
{
case STD_INPUT_HANDLE:
hFile = NtCurrentPeb()->ProcessParameters->InputHandle;
break;
case STD_OUTPUT_HANDLE:
hFile = NtCurrentPeb()->ProcessParameters->OutputHandle;
break;
case STD_ERROR_HANDLE:
hFile = NtCurrentPeb()->ProcessParameters->ErrorHandle;
break;
}
/* check console handles */
if (((ULONG)hFile & 3) == 3)
{
// if (VerifyConsoleHandle(hFile))
return FILE_TYPE_CHAR;
}
Status = NtQueryVolumeInformationFile(hFile,
&StatusBlock,
&DeviceInfo,
sizeof(FILE_FS_DEVICE_INFORMATION),
FileFsDeviceInformation);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FILE_TYPE_UNKNOWN;
}
switch (DeviceInfo.DeviceType)
{
case FILE_DEVICE_CD_ROM:
case FILE_DEVICE_CD_ROM_FILE_SYSTEM:
case FILE_DEVICE_CONTROLLER:
case FILE_DEVICE_DATALINK:
case FILE_DEVICE_DFS:
case FILE_DEVICE_DISK:
case FILE_DEVICE_DISK_FILE_SYSTEM:
case FILE_DEVICE_VIRTUAL_DISK:
return FILE_TYPE_DISK;
case FILE_DEVICE_KEYBOARD:
case FILE_DEVICE_MOUSE:
case FILE_DEVICE_NULL:
case FILE_DEVICE_PARALLEL_PORT:
case FILE_DEVICE_PRINTER:
case FILE_DEVICE_SERIAL_PORT:
case FILE_DEVICE_SCREEN:
case FILE_DEVICE_SOUND:
case FILE_DEVICE_MODEM:
return FILE_TYPE_CHAR;
case FILE_DEVICE_NAMED_PIPE:
return FILE_TYPE_PIPE;
}
return FILE_TYPE_UNKNOWN; return FILE_TYPE_UNKNOWN;
} }
@ -267,19 +332,29 @@ DWORD STDCALL GetFileSize(HANDLE hFile,
DWORD STDCALL GetCompressedFileSizeA(LPCSTR lpFileName, DWORD STDCALL GetCompressedFileSizeA(LPCSTR lpFileName,
LPDWORD lpFileSizeHigh) LPDWORD lpFileSizeHigh)
{ {
WCHAR FileNameW[MAX_PATH]; UNICODE_STRING FileNameU;
ULONG i; ANSI_STRING FileName;
DWORD Size;
i = 0; RtlInitAnsiString(&FileName,
while ((*lpFileName)!=0 && i < MAX_PATH) (LPSTR)lpFileName);
{
FileNameW[i] = *lpFileName;
lpFileName++;
i++;
}
FileNameW[i] = 0;
return GetCompressedFileSizeW(FileNameW,lpFileSizeHigh); /* convert ansi (or oem) string to unicode */
if (bIsFileApiAnsi)
RtlAnsiStringToUnicodeString(&FileNameU,
&FileName,
TRUE);
else
RtlOemStringToUnicodeString(&FileNameU,
&FileName,
TRUE);
Size = GetCompressedFileSizeW(FileNameU.Buffer,
lpFileSizeHigh);
RtlFreeUnicodeString (&FileNameU);
return Size;
} }
@ -412,9 +487,7 @@ GetFileAttributesA (
Result = GetFileAttributesW (FileNameU.Buffer); Result = GetFileAttributesW (FileNameU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (), RtlFreeUnicodeString (&FileNameU);
0,
FileNameU.Buffer);
return Result; return Result;
} }
@ -482,9 +555,7 @@ SetFileAttributesA (
Result = SetFileAttributesW (FileNameU.Buffer, Result = SetFileAttributesW (FileNameU.Buffer,
dwFileAttributes); dwFileAttributes);
RtlFreeHeap (RtlGetProcessHeap (), RtlFreeUnicodeString (&FileNameU);
0,
FileNameU.Buffer);
return Result; return Result;
} }