mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 21:46:05 +00:00
Rewrote OpenFile().
svn path=/trunk/; revision=2809
This commit is contained in:
parent
e806f90b71
commit
6c10b3528a
1 changed files with 35 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: file.c,v 1.29 2002/03/25 21:07:17 hbirr Exp $
|
/* $Id: file.c,v 1.30 2002/04/01 22:06:51 hbirr 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
|
||||||
|
@ -68,44 +68,54 @@ OpenFile(LPCSTR lpFileName,
|
||||||
PWCHAR FilePart;
|
PWCHAR FilePart;
|
||||||
ULONG Len;
|
ULONG Len;
|
||||||
|
|
||||||
|
DPRINT("OpenFile('%s', lpReOpenBuff %x, uStyle %x)\n", lpFileName, lpReOpenBuff, uStyle);
|
||||||
|
|
||||||
if (lpReOpenBuff == NULL)
|
if (lpReOpenBuff == NULL)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlInitAnsiString (&FileName,
|
RtlInitAnsiString (&FileName, (LPSTR)lpFileName);
|
||||||
(LPSTR)lpFileName);
|
|
||||||
|
|
||||||
/* convert ansi (or oem) string to unicode */
|
/* convert ansi (or oem) string to unicode */
|
||||||
if (bIsFileApiAnsi)
|
if (bIsFileApiAnsi)
|
||||||
RtlAnsiStringToUnicodeString (&FileNameU,
|
RtlAnsiStringToUnicodeString (&FileNameU, &FileName, TRUE);
|
||||||
&FileName,
|
|
||||||
TRUE);
|
|
||||||
else
|
else
|
||||||
RtlOemStringToUnicodeString (&FileNameU,
|
RtlOemStringToUnicodeString (&FileNameU, &FileName, TRUE);
|
||||||
&FileName,
|
|
||||||
TRUE);
|
|
||||||
|
|
||||||
Len = SearchPathW (NULL,
|
Len = SearchPathW (NULL,
|
||||||
FileNameU.Buffer,
|
FileNameU.Buffer,
|
||||||
NULL,
|
NULL,
|
||||||
MAX_PATH,
|
OFS_MAXPATHNAME,
|
||||||
PathNameW,
|
PathNameW,
|
||||||
&FilePart);
|
&FilePart);
|
||||||
|
|
||||||
RtlFreeHeap (RtlGetProcessHeap (),
|
RtlFreeUnicodeString(&FileNameU);
|
||||||
0,
|
|
||||||
FileNameU.Buffer);
|
|
||||||
|
|
||||||
if (Len == 0)
|
if (Len == 0 || Len > OFS_MAXPATHNAME)
|
||||||
return (HFILE)NULL;
|
{
|
||||||
|
return (HFILE)INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (Len > MAX_PATH)
|
FileName.Buffer = lpReOpenBuff->szPathName;
|
||||||
return (HFILE)NULL;
|
FileName.Length = 0;
|
||||||
|
FileName.MaximumLength = OFS_MAXPATHNAME;
|
||||||
|
|
||||||
FileNameString.Length = lstrlenW(PathNameW) * sizeof(WCHAR);
|
RtlInitUnicodeString(&FileNameU, PathNameW);
|
||||||
FileNameString.Buffer = PathNameW;
|
|
||||||
FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR);
|
/* convert unicode string to ansi (or oem) */
|
||||||
|
if (bIsFileApiAnsi)
|
||||||
|
RtlUnicodeStringToAnsiString (&FileName, &FileNameU, FALSE);
|
||||||
|
else
|
||||||
|
RtlUnicodeStringToOemString (&FileName, &FileNameU, FALSE);
|
||||||
|
|
||||||
|
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)PathNameW,
|
||||||
|
&FileNameString,
|
||||||
|
NULL,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
return (HFILE)INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
|
@ -118,7 +128,10 @@ OpenFile(LPCSTR lpFileName,
|
||||||
// FILE_NO_INTERMEDIATE_BUFFERING
|
// FILE_NO_INTERMEDIATE_BUFFERING
|
||||||
|
|
||||||
if ((uStyle & OF_PARSE) == OF_PARSE)
|
if ((uStyle & OF_PARSE) == OF_PARSE)
|
||||||
|
{
|
||||||
|
RtlFreeUnicodeString(&FileNameString);
|
||||||
return (HFILE)NULL;
|
return (HFILE)NULL;
|
||||||
|
}
|
||||||
|
|
||||||
errCode = NtOpenFile (&FileHandle,
|
errCode = NtOpenFile (&FileHandle,
|
||||||
GENERIC_READ|SYNCHRONIZE,
|
GENERIC_READ|SYNCHRONIZE,
|
||||||
|
@ -127,6 +140,8 @@ OpenFile(LPCSTR lpFileName,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
FILE_NON_DIRECTORY_FILE);
|
FILE_NON_DIRECTORY_FILE);
|
||||||
|
|
||||||
|
RtlFreeUnicodeString(&FileNameString);
|
||||||
|
|
||||||
lpReOpenBuff->nErrCode = RtlNtStatusToDosError(errCode);
|
lpReOpenBuff->nErrCode = RtlNtStatusToDosError(errCode);
|
||||||
|
|
||||||
if (!NT_SUCCESS(errCode))
|
if (!NT_SUCCESS(errCode))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue