Fixed ANSI/OEM <--> Unicode conversions

svn path=/trunk/; revision=1059
This commit is contained in:
Eric Kohl 2000-03-15 18:30:30 +00:00
parent b2eb99d9f7
commit 67200bd4f9
5 changed files with 623 additions and 521 deletions

View file

@ -1,4 +1,4 @@
/* $Id: dir.c,v 1.24 2000/02/18 00:49:39 ekohl Exp $ /* $Id: dir.c,v 1.25 2000/03/15 18:28:58 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
@ -27,294 +27,278 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
WINBOOL STDCALL CreateDirectoryA(LPCSTR lpPathName, WINBOOL
LPSECURITY_ATTRIBUTES lpSecurityAttributes) STDCALL
CreateDirectoryA (
LPCSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{ {
return CreateDirectoryExA(NULL,lpPathName,lpSecurityAttributes); return CreateDirectoryExA (NULL,
lpPathName,
lpSecurityAttributes);
} }
WINBOOL STDCALL CreateDirectoryExA(LPCSTR lpTemplateDirectory, WINBOOL
LPCSTR lpNewDirectory, STDCALL
LPSECURITY_ATTRIBUTES lpSecurityAttributes) CreateDirectoryExA (
LPCSTR lpTemplateDirectory,
LPCSTR lpNewDirectory,
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{ {
WCHAR TemplateDirectoryW[MAX_PATH]; UNICODE_STRING TmplDirU;
WCHAR NewDirectoryW[MAX_PATH]; UNICODE_STRING NewDirU;
ULONG i; ANSI_STRING TmplDir;
ANSI_STRING NewDir;
WINBOOL Result;
DPRINT("lpTemplateDirectory %s lpNewDirectory %s lpSecurityAttributes %p\n", RtlInitUnicodeString (&TmplDirU,
lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes); NULL);
if (lpTemplateDirectory) RtlInitUnicodeString (&NewDirU,
{ NULL);
i = 0;
while ((*lpTemplateDirectory)!=0 && i < MAX_PATH)
{
TemplateDirectoryW[i] = *lpTemplateDirectory;
lpTemplateDirectory++;
i++;
}
TemplateDirectoryW[i] = 0;
}
DPRINT ("\n");
if (lpNewDirectory) if (lpTemplateDirectory != NULL)
{
i = 0;
while ((*lpNewDirectory)!=0 && i < MAX_PATH)
{
NewDirectoryW[i] = *lpNewDirectory;
lpNewDirectory++;
i++;
}
NewDirectoryW[i] = 0;
}
DPRINT ("\n");
return CreateDirectoryExW(lpTemplateDirectory?TemplateDirectoryW:NULL,
lpNewDirectory?NewDirectoryW:NULL,
lpSecurityAttributes);
}
WINBOOL STDCALL CreateDirectoryW(LPCWSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
return CreateDirectoryExW(NULL,lpPathName,lpSecurityAttributes);
}
WINBOOL STDCALL CreateDirectoryExW(LPCWSTR lpTemplateDirectory,
LPCWSTR lpNewDirectory,
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
NTSTATUS errCode;
HANDLE DirectoryHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DirectoryNameString;
IO_STATUS_BLOCK IoStatusBlock;
WCHAR PathNameW[MAX_PATH];
WCHAR DirectoryNameW[MAX_PATH];
UINT Len = 0;
DPRINT("lpTemplateDirectory %S lpNewDirectory %S lpSecurityAttributes %p\n",
lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes);
if ( lpTemplateDirectory != NULL && *lpTemplateDirectory != 0 )
{
// get object attributes from template directory
DPRINT("KERNEL32:FIXME:%s:%d\n",__FILE__,__LINE__);
return(FALSE);
}
if (lpNewDirectory[1] == (WCHAR)':')
{
wcscpy(PathNameW, lpNewDirectory);
}
else if (wcslen(lpNewDirectory) > 4 &&
lpNewDirectory[0] == (WCHAR)'\\' &&
lpNewDirectory[1] == (WCHAR)'\\' &&
lpNewDirectory[2] == (WCHAR)'.' &&
lpNewDirectory[3] == (WCHAR)'\\')
{
wcscpy(PathNameW, lpNewDirectory);
}
else if (lpNewDirectory[0] == (WCHAR)'\\')
{
GetCurrentDirectoryW(MAX_PATH,PathNameW);
PathNameW[3] = 0;
wcscat(PathNameW, lpNewDirectory);
}
else
{
Len = GetCurrentDirectoryW(MAX_PATH,PathNameW);
if ( Len == 0 )
return FALSE;
if ( PathNameW[Len-1] != L'\\' ) {
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
}
wcscat(PathNameW,lpNewDirectory);
}
DirectoryNameW[0] = '\\';
DirectoryNameW[1] = '?';
DirectoryNameW[2] = '?';
DirectoryNameW[3] = '\\';
DirectoryNameW[4] = 0;
wcscat(DirectoryNameW,PathNameW);
DirectoryNameString.Length = wcslen (DirectoryNameW)*sizeof(WCHAR);
if ( DirectoryNameString.Length == 0 )
return FALSE;
if ( DirectoryNameString.Length > MAX_PATH*sizeof(WCHAR) )
return FALSE;
DirectoryNameString.Buffer = (WCHAR *)DirectoryNameW;
DirectoryNameString.MaximumLength = DirectoryNameString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &DirectoryNameString;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL;
errCode = NtCreateFile(&DirectoryHandle,
DIRECTORY_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
NULL,
FILE_ATTRIBUTE_DIRECTORY,
0,
FILE_CREATE,
FILE_DIRECTORY_FILE,
NULL,
0);
DPRINT("errCode: %x\n", errCode);
if (!NT_SUCCESS(errCode))
{
SetLastError(RtlNtStatusToDosError(errCode));
return FALSE;
}
NtClose(DirectoryHandle);
return TRUE;
}
WINBOOL STDCALL RemoveDirectoryA(LPCSTR lpPathName)
{
WCHAR PathNameW[MAX_PATH];
ULONG i;
i = 0;
while ((*lpPathName)!=0 && i < MAX_PATH)
{ {
PathNameW[i] = *lpPathName; RtlInitAnsiString (&TmplDir,
lpPathName++; (LPSTR)lpTemplateDirectory);
i++;
/* convert ansi (or oem) string to unicode */
if (bIsFileApiAnsi)
RtlAnsiStringToUnicodeString (&TmplDirU,
&TmplDir,
TRUE);
else
RtlOemStringToUnicodeString (&TmplDirU,
&TmplDir,
TRUE);
} }
PathNameW[i] = 0;
return RemoveDirectoryW(PathNameW); if (lpNewDirectory != NULL)
{
RtlInitAnsiString (&NewDir,
(LPSTR)lpNewDirectory);
/* convert ansi (or oem) string to unicode */
if (bIsFileApiAnsi)
RtlAnsiStringToUnicodeString (&NewDirU,
&NewDir,
TRUE);
else
RtlOemStringToUnicodeString (&NewDirU,
&NewDir,
TRUE);
}
Result = CreateDirectoryExW (TmplDirU.Buffer,
NewDirU.Buffer,
lpSecurityAttributes);
if (lpTemplateDirectory != NULL)
RtlFreeHeap (RtlGetProcessHeap (),
0,
TmplDirU.Buffer);
if (lpNewDirectory != NULL)
RtlFreeHeap (RtlGetProcessHeap (),
0,
NewDirU.Buffer);
return Result;
} }
WINBOOL STDCALL RemoveDirectoryW(LPCWSTR lpPathName) WINBOOL
STDCALL
CreateDirectoryW (
LPCWSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{ {
NTSTATUS errCode; return CreateDirectoryExW (NULL,
HANDLE DirectoryHandle; lpPathName,
IO_STATUS_BLOCK IoStatusBlock; lpSecurityAttributes);
OBJECT_ATTRIBUTES ObjectAttributes; }
UNICODE_STRING DirectoryNameString;
WCHAR PathNameW[MAX_PATH];
WCHAR DirectoryNameW[MAX_PATH];
FILE_DISPOSITION_INFORMATION FileDispInfo;
UINT Len = 0;
DPRINT("lpPathName %S\n",
lpPathName);
if (lpPathName[1] == (WCHAR)':')
{ WINBOOL
wcscpy(PathNameW, lpPathName); STDCALL
} CreateDirectoryExW (
else if (wcslen(lpPathName) > 4 && LPCWSTR lpTemplateDirectory,
lpPathName[0] == (WCHAR)'\\' && LPCWSTR lpNewDirectory,
lpPathName[1] == (WCHAR)'\\' && LPSECURITY_ATTRIBUTES lpSecurityAttributes
lpPathName[2] == (WCHAR)'.' && )
lpPathName[3] == (WCHAR)'\\') {
{ OBJECT_ATTRIBUTES ObjectAttributes;
wcscpy(PathNameW, lpPathName); IO_STATUS_BLOCK IoStatusBlock;
} UNICODE_STRING NtPathU;
else if (lpPathName[0] == (WCHAR)'\\') HANDLE DirectoryHandle;
{ NTSTATUS Status;
GetCurrentDirectoryW(MAX_PATH,PathNameW);
wcscpy (&PathNameW[2], lpPathName); DPRINT ("lpTemplateDirectory %S lpNewDirectory %S lpSecurityAttributes %p\n",
} lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes);
else
{ if (lpTemplateDirectory != NULL && *lpTemplateDirectory != 0)
Len = GetCurrentDirectoryW(MAX_PATH,PathNameW); {
if ( Len == 0 ) // get object attributes from template directory
return FALSE; DPRINT("KERNEL32:FIXME:%s:%d\n",__FILE__,__LINE__);
if ( PathNameW[Len-1] != L'\\' ) { return FALSE;
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
} }
wcscat(PathNameW,lpPathName);
}
DirectoryNameW[0] = '\\'; if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpNewDirectory,
DirectoryNameW[1] = '?'; &NtPathU,
DirectoryNameW[2] = '?'; NULL,
DirectoryNameW[3] = '\\'; NULL))
DirectoryNameW[4] = 0; return FALSE;
wcscat(DirectoryNameW,PathNameW);
DirectoryNameString.Length = wcslen (DirectoryNameW)*sizeof(WCHAR); DPRINT1 ("NtPathU \'%wZ\'\n", &NtPathU);
if ( DirectoryNameString.Length == 0 ) ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
return FALSE; ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &NtPathU;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL;
if ( DirectoryNameString.Length > MAX_PATH*sizeof(WCHAR) ) Status = NtCreateFile (&DirectoryHandle,
return FALSE; DIRECTORY_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
NULL,
FILE_ATTRIBUTE_DIRECTORY,
0,
FILE_CREATE,
FILE_DIRECTORY_FILE,
NULL,
0);
DPRINT("Status: %lx\n", Status);
DirectoryNameString.Buffer = (WCHAR *)DirectoryNameW; RtlFreeHeap (RtlGetProcessHeap (),
DirectoryNameString.MaximumLength = DirectoryNameString.Length + sizeof(WCHAR); 0,
NtPathU.Buffer);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); if (!NT_SUCCESS(Status))
ObjectAttributes.RootDirectory = NULL; {
ObjectAttributes.ObjectName = &DirectoryNameString; SetLastError(RtlNtStatusToDosError(Status));
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; return FALSE;
ObjectAttributes.SecurityDescriptor = NULL; }
ObjectAttributes.SecurityQualityOfService = NULL;
DPRINT("DirectoryNameW '%S'\n", DirectoryNameW); NtClose (DirectoryHandle);
errCode = NtCreateFile(&DirectoryHandle, return TRUE;
FILE_WRITE_ATTRIBUTES, /* 0x110080 */ }
&ObjectAttributes,
&IoStatusBlock,
NULL,
FILE_ATTRIBUTE_DIRECTORY, /* 0x7 */
0,
FILE_OPEN,
FILE_DIRECTORY_FILE, /* 0x204021 */
NULL,
0);
if (!NT_SUCCESS(errCode))
{
CHECKPOINT;
SetLastError(RtlNtStatusToDosError(errCode));
return FALSE;
}
FileDispInfo.DeleteFile = TRUE; WINBOOL
STDCALL
RemoveDirectoryA (
LPCSTR lpPathName
)
{
UNICODE_STRING PathNameU;
ANSI_STRING PathName;
WINBOOL Result;
errCode = NtSetInformationFile(DirectoryHandle, RtlInitAnsiString (&PathName,
&IoStatusBlock, (LPSTR)lpPathName);
&FileDispInfo,
sizeof(FILE_DISPOSITION_INFORMATION),
FileDispositionInformation);
if (!NT_SUCCESS(errCode)) /* convert ansi (or oem) string to unicode */
{ if (bIsFileApiAnsi)
CHECKPOINT; RtlAnsiStringToUnicodeString (&PathNameU,
NtClose(DirectoryHandle); &PathName,
SetLastError(RtlNtStatusToDosError(errCode)); TRUE);
return FALSE; else
} RtlOemStringToUnicodeString (&PathNameU,
&PathName,
TRUE);
errCode = NtClose(DirectoryHandle); Result = RemoveDirectoryW (PathNameU.Buffer);
if (!NT_SUCCESS(errCode)) RtlFreeHeap (RtlGetProcessHeap (),
{ 0,
CHECKPOINT; PathNameU.Buffer);
SetLastError(RtlNtStatusToDosError(errCode));
return FALSE;
}
return TRUE; return Result;
}
WINBOOL
STDCALL
RemoveDirectoryW (
LPCWSTR lpPathName
)
{
FILE_DISPOSITION_INFORMATION FileDispInfo;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING NtPathU;
HANDLE DirectoryHandle;
NTSTATUS Status;
DPRINT("lpPathName %S\n", lpPathName);
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpPathName,
&NtPathU,
NULL,
NULL))
return FALSE;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &NtPathU;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL;
DPRINT("NtPathU '%S'\n", NtPathU.Buffer);
Status = NtCreateFile (&DirectoryHandle,
FILE_WRITE_ATTRIBUTES, /* 0x110080 */
&ObjectAttributes,
&IoStatusBlock,
NULL,
FILE_ATTRIBUTE_DIRECTORY, /* 0x7 */
0,
FILE_OPEN,
FILE_DIRECTORY_FILE, /* 0x204021 */
NULL,
0);
RtlFreeHeap (RtlGetProcessHeap (),
0,
NtPathU.Buffer);
if (!NT_SUCCESS(Status))
{
CHECKPOINT;
SetLastError (RtlNtStatusToDosError (Status));
return FALSE;
}
FileDispInfo.DeleteFile = TRUE;
Status = NtSetInformationFile (DirectoryHandle,
&IoStatusBlock,
&FileDispInfo,
sizeof(FILE_DISPOSITION_INFORMATION),
FileDispositionInformation);
if (!NT_SUCCESS(Status))
{
CHECKPOINT;
NtClose(DirectoryHandle);
SetLastError (RtlNtStatusToDosError (Status));
return FALSE;
}
Status = NtClose (DirectoryHandle);
if (!NT_SUCCESS(Status))
{
CHECKPOINT;
SetLastError (RtlNtStatusToDosError (Status));
return FALSE;
}
return TRUE;
} }
@ -341,14 +325,9 @@ GetFullPathNameA (
RtlInitAnsiString (&FileName, RtlInitAnsiString (&FileName,
(LPSTR)lpFileName); (LPSTR)lpFileName);
if (bIsFileApiAnsi) RtlAnsiStringToUnicodeString (&FileNameU,
RtlAnsiStringToUnicodeString (&FileNameU, &FileName,
&FileName, TRUE);
TRUE);
else
RtlOemStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
BufferLength = nBufferLength * sizeof(WCHAR); BufferLength = nBufferLength * sizeof(WCHAR);
@ -369,15 +348,9 @@ GetFullPathNameA (
FullName.Length = 0; FullName.Length = 0;
FullName.Buffer = lpBuffer; FullName.Buffer = lpBuffer;
/* convert unicode to ansi (or oem) */ RtlUnicodeStringToAnsiString (&FullName,
if (bIsFileApiAnsi) &FullNameU,
RtlUnicodeStringToAnsiString (&FullName, FALSE);
&FullNameU,
FALSE);
else
RtlUnicodeStringToOemString (&FullName,
&FullNameU,
FALSE);
if (lpFilePart != NULL) if (lpFilePart != NULL)
{ {
@ -424,14 +397,14 @@ GetFullPathNameW (
DWORD DWORD
STDCALL STDCALL
GetShortPathNameA( GetShortPathNameA (
LPCSTR lpszLongPath, LPCSTR lpszLongPath,
LPSTR lpszShortPath, LPSTR lpszShortPath,
DWORD cchBuffer DWORD cchBuffer
) )
{ {
//1 remove unicode chars and spaces //1 remove unicode chars and spaces
//2 remove preceding and trailing periods. //2 remove preceding and trailing periods.
//3 remove embedded periods except the last one //3 remove embedded periods except the last one
//4 Split the string in two parts before and after the period //4 Split the string in two parts before and after the period
@ -441,81 +414,134 @@ GetShortPathNameA(
//4 Increment the ~1 string if the resulting name allready exists //4 Increment the ~1 string if the resulting name allready exists
return 0;
} }
DWORD DWORD
STDCALL STDCALL
GetShortPathNameW( GetShortPathNameW (
LPCWSTR lpszLongPath, LPCWSTR lpszLongPath,
LPWSTR lpszShortPath, LPWSTR lpszShortPath,
DWORD cchBuffer DWORD cchBuffer
) )
{ {
return 0;
} }
DWORD DWORD
STDCALL STDCALL
SearchPathA( SearchPathA (
LPCSTR lpPath, LPCSTR lpPath,
LPCSTR lpFileName, LPCSTR lpFileName,
LPCSTR lpExtension, LPCSTR lpExtension,
DWORD nBufferLength, DWORD nBufferLength,
LPSTR lpBuffer, LPSTR lpBuffer,
LPSTR *lpFilePart LPSTR *lpFilePart
) )
{ {
WCHAR PathW[MAX_PATH]; UNICODE_STRING PathU;
WCHAR FileNameW[MAX_PATH]; UNICODE_STRING FileNameU;
WCHAR ExtensionW[MAX_PATH]; UNICODE_STRING ExtensionU;
UNICODE_STRING BufferU;
WCHAR BufferW[MAX_PATH]; ANSI_STRING Path;
WCHAR *FilePartW; ANSI_STRING FileName;
ANSI_STRING Extension;
ULONG i; ANSI_STRING Buffer;
PWCHAR FilePartW;
DWORD RetValue; DWORD RetValue;
i = 0; RtlInitAnsiString (&Path,
while ((*lpPath)!=0 && i < MAX_PATH) (LPSTR)lpPath);
RtlInitAnsiString (&FileName,
(LPSTR)lpFileName);
RtlInitAnsiString (&Extension,
(LPSTR)lpExtension);
/* convert ansi (or oem) strings to unicode */
if (bIsFileApiAnsi)
{ {
PathW[i] = *lpPath; RtlAnsiStringToUnicodeString (&PathU,
lpPath++; &Path,
i++; TRUE);
RtlAnsiStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
RtlAnsiStringToUnicodeString (&ExtensionU,
&Extension,
TRUE);
} }
PathW[i] = 0; else
i = 0;
while ((*lpFileName)!=0 && i < MAX_PATH)
{ {
FileNameW[i] = *lpFileName; RtlOemStringToUnicodeString (&PathU,
lpFileName++; &Path,
i++; TRUE);
RtlOemStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
RtlOemStringToUnicodeString (&ExtensionU,
&Extension,
TRUE);
} }
FileNameW[i] = 0;
i = 0; BufferU.Length = 0;
while ((*lpExtension)!=0 && i < MAX_PATH) BufferU.MaximumLength = nBufferLength * sizeof(WCHAR);
{ BufferU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
ExtensionW[i] = *lpExtension; 0,
lpExtension++; BufferU.MaximumLength);
i++;
}
ExtensionW[i] = 0;
RetValue = SearchPathW(PathW,FileNameW,ExtensionW,nBufferLength,BufferW,&FilePartW); Buffer.Length = 0;
for(i=0;i<nBufferLength;i++) Buffer.MaximumLength = nBufferLength;
lpBuffer[i] = (char)BufferW[i]; Buffer.Buffer = lpBuffer;
RetValue = SearchPathW (PathU.Buffer,
FileNameU.Buffer,
ExtensionU.Buffer,
nBufferLength,
BufferU.Buffer,
&FilePartW);
RtlFreeHeap (RtlGetProcessHeap (),
0,
PathU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
FileNameU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
ExtensionU.Buffer);
/* convert ansi (or oem) string to unicode */
if (bIsFileApiAnsi)
RtlUnicodeStringToAnsiString (&Buffer,
&BufferU,
FALSE);
else
RtlUnicodeStringToOemString (&Buffer,
&BufferU,
FALSE);
RtlFreeHeap (RtlGetProcessHeap (),
0,
BufferU.Buffer);
*lpFilePart = strrchr (lpBuffer, '\\') + 1;
*lpFilePart = strrchr(lpBuffer,'\\')+1;
return RetValue; return RetValue;
} }
DWORD STDCALL SearchPathW(LPCWSTR lpPath,
LPCWSTR lpFileName, DWORD
LPCWSTR lpExtension, STDCALL
DWORD nBufferLength, SearchPathW (
LPWSTR lpBuffer, LPCWSTR lpPath,
LPWSTR *lpFilePart) LPCWSTR lpFileName,
LPCWSTR lpExtension,
DWORD nBufferLength,
LPWSTR lpBuffer,
LPWSTR *lpFilePart
)
/* /*
* FUNCTION: Searches for the specified file * FUNCTION: Searches for the specified file
* ARGUMENTS: * ARGUMENTS:

View file

@ -29,93 +29,123 @@ WINBOOL bIsFileApiAnsi = TRUE; // set the file api to ansi or oem
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
VOID STDCALL SetFileApisToOEM(VOID) VOID
STDCALL
SetFileApisToOEM (
VOID
)
{ {
bIsFileApiAnsi = FALSE; bIsFileApiAnsi = FALSE;
} }
VOID STDCALL SetFileApisToANSI(VOID) VOID
STDCALL
SetFileApisToANSI (
VOID
)
{ {
bIsFileApiAnsi = TRUE; bIsFileApiAnsi = TRUE;
} }
WINBOOL STDCALL AreFileApisANSI(VOID) WINBOOL
STDCALL
AreFileApisANSI (
VOID
)
{ {
return (bIsFileApiAnsi); return bIsFileApiAnsi;
} }
HFILE STDCALL OpenFile(LPCSTR lpFileName, HFILE
LPOFSTRUCT lpReOpenBuff, STDCALL
UINT uStyle) OpenFile (
LPCSTR lpFileName,
LPOFSTRUCT lpReOpenBuff,
UINT uStyle
)
{ {
NTSTATUS errCode; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE FileHandle = NULL; IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING FileNameString; UNICODE_STRING FileNameString;
WCHAR FileNameW[MAX_PATH]; UNICODE_STRING FileNameU;
WCHAR PathNameW[MAX_PATH]; ANSI_STRING FileName;
ULONG i; WCHAR PathNameW[MAX_PATH];
OBJECT_ATTRIBUTES ObjectAttributes; HANDLE FileHandle = NULL;
IO_STATUS_BLOCK IoStatusBlock; NTSTATUS errCode;
WCHAR *FilePart; PWCHAR FilePart;
ULONG Len; ULONG Len;
if (lpReOpenBuff == NULL)
{
return FALSE;
}
i = 0;
while ((*lpFileName)!=0 && i < MAX_PATH)
{
FileNameW[i] = *lpFileName;
lpFileName++;
i++;
}
FileNameW[i] = 0;
Len = SearchPathW(NULL,FileNameW,NULL,MAX_PATH,PathNameW,&FilePart); if (lpReOpenBuff == NULL)
if ( Len == 0 ) {
return (HFILE)NULL; return FALSE;
}
if ( Len > MAX_PATH ) RtlInitAnsiString (&FileName,
return (HFILE)NULL; (LPSTR)lpFileName);
FileNameString.Length = lstrlenW(PathNameW)*sizeof(WCHAR);
FileNameString.Buffer = PathNameW;
FileNameString.MaximumLength = FileNameString.Length+sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &FileNameString;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL;
// FILE_SHARE_READ /* convert ansi (or oem) string to unicode */
// FILE_NO_INTERMEDIATE_BUFFERING if (bIsFileApiAnsi)
RtlAnsiStringToUnicodeString (&FileNameU,
if ((uStyle & OF_PARSE) == OF_PARSE ) &FileName,
return (HFILE)NULL; TRUE);
else
errCode = NtOpenFile(&FileHandle, RtlOemStringToUnicodeString (&FileNameU,
GENERIC_READ|SYNCHRONIZE, &FileName,
&ObjectAttributes, TRUE);
&IoStatusBlock,
FILE_SHARE_READ, Len = SearchPathW (NULL,
FILE_NON_DIRECTORY_FILE); FileNameU.Buffer,
NULL,
lpReOpenBuff->nErrCode = RtlNtStatusToDosError(errCode); MAX_PATH,
PathNameW,
if (!NT_SUCCESS(errCode)) &FilePart);
{
SetLastError(RtlNtStatusToDosError(errCode)); RtlFreeHeap (RtlGetProcessHeap (),
return (HFILE)INVALID_HANDLE_VALUE; 0,
} FileNameU.Buffer);
return (HFILE)FileHandle; if (Len == 0)
return (HFILE)NULL;
if (Len > MAX_PATH)
return (HFILE)NULL;
FileNameString.Length = lstrlenW(PathNameW) * sizeof(WCHAR);
FileNameString.Buffer = PathNameW;
FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &FileNameString;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL;
// FILE_SHARE_READ
// FILE_NO_INTERMEDIATE_BUFFERING
if ((uStyle & OF_PARSE) == OF_PARSE)
return (HFILE)NULL;
errCode = NtOpenFile (&FileHandle,
GENERIC_READ|SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ,
FILE_NON_DIRECTORY_FILE);
lpReOpenBuff->nErrCode = RtlNtStatusToDosError(errCode);
if (!NT_SUCCESS(errCode))
{
SetLastError (RtlNtStatusToDosError (errCode));
return (HFILE)INVALID_HANDLE_VALUE;
}
return (HFILE)FileHandle;
} }
@ -123,10 +153,10 @@ WINBOOL STDCALL FlushFileBuffers(HANDLE hFile)
{ {
NTSTATUS errCode; NTSTATUS errCode;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
errCode = NtFlushBuffersFile(hFile, errCode = NtFlushBuffersFile(hFile,
&IoStatusBlock); &IoStatusBlock);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError(RtlNtStatusToDosError(errCode));
return(FALSE); return(FALSE);
@ -152,16 +182,16 @@ DWORD STDCALL SetFilePointer(HANDLE hFile,
Distance.u.LowPart = lDistanceToMove; Distance.u.LowPart = lDistanceToMove;
Distance.u.HighPart = (lpDistanceToMoveHigh) ? *lpDistanceToMoveHigh : 0; Distance.u.HighPart = (lpDistanceToMoveHigh) ? *lpDistanceToMoveHigh : 0;
if (dwMoveMethod == FILE_CURRENT) if (dwMoveMethod == FILE_CURRENT)
{ {
NtQueryInformationFile(hFile, NtQueryInformationFile(hFile,
&IoStatusBlock, &IoStatusBlock,
&FilePosition, &FilePosition,
sizeof(FILE_POSITION_INFORMATION), sizeof(FILE_POSITION_INFORMATION),
FilePositionInformation); FilePositionInformation);
FilePosition.CurrentByteOffset.QuadPart += Distance.QuadPart; FilePosition.CurrentByteOffset.QuadPart += Distance.QuadPart;
} }
else if (dwMoveMethod == FILE_END) else if (dwMoveMethod == FILE_END)
{ {
NtQueryInformationFile(hFile, NtQueryInformationFile(hFile,
&IoStatusBlock, &IoStatusBlock,
@ -171,17 +201,17 @@ DWORD STDCALL SetFilePointer(HANDLE hFile,
FilePosition.CurrentByteOffset.QuadPart = FilePosition.CurrentByteOffset.QuadPart =
FileEndOfFile.EndOfFile.QuadPart - Distance.QuadPart; FileEndOfFile.EndOfFile.QuadPart - Distance.QuadPart;
} }
else if ( dwMoveMethod == FILE_BEGIN ) else if ( dwMoveMethod == FILE_BEGIN )
{ {
FilePosition.CurrentByteOffset.QuadPart = Distance.QuadPart; FilePosition.CurrentByteOffset.QuadPart = Distance.QuadPart;
} }
errCode = NtSetInformationFile(hFile, errCode = NtSetInformationFile(hFile,
&IoStatusBlock, &IoStatusBlock,
&FilePosition, &FilePosition,
sizeof(FILE_POSITION_INFORMATION), sizeof(FILE_POSITION_INFORMATION),
FilePositionInformation); FilePositionInformation);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError(RtlNtStatusToDosError(errCode));
return -1; return -1;
@ -201,7 +231,7 @@ DWORD STDCALL GetFileType(HANDLE hFile)
} }
DWORD STDCALL GetFileSize(HANDLE hFile, DWORD STDCALL GetFileSize(HANDLE hFile,
LPDWORD lpFileSizeHigh) LPDWORD lpFileSizeHigh)
{ {
NTSTATUS errCode; NTSTATUS errCode;
@ -355,20 +385,36 @@ WINBOOL STDCALL GetFileInformationByHandle(HANDLE hFile,
} }
DWORD STDCALL GetFileAttributesA(LPCSTR lpFileName) DWORD
STDCALL
GetFileAttributesA (
LPCSTR lpFileName
)
{ {
ULONG i; UNICODE_STRING FileNameU;
WCHAR FileNameW[MAX_PATH]; ANSI_STRING FileName;
WINBOOL Result;
i = 0;
while ((*lpFileName)!=0 && i < MAX_PATH) RtlInitAnsiString (&FileName,
{ (LPSTR)lpFileName);
FileNameW[i] = *lpFileName;
lpFileName++; /* convert ansi (or oem) string to unicode */
i++; if (bIsFileApiAnsi)
} RtlAnsiStringToUnicodeString (&FileNameU,
FileNameW[i] = 0; &FileName,
return GetFileAttributesW(FileNameW); TRUE);
else
RtlOemStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
Result = GetFileAttributesW (FileNameU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
FileNameU.Buffer);
return Result;
} }
@ -407,20 +453,38 @@ DWORD STDCALL GetFileAttributesW(LPCWSTR lpFileName)
} }
WINBOOL STDCALL SetFileAttributesA(LPCSTR lpFileName, WINBOOL
DWORD dwFileAttributes) STDCALL
SetFileAttributesA (
LPCSTR lpFileName,
DWORD dwFileAttributes
)
{ {
ULONG i; UNICODE_STRING FileNameU;
WCHAR FileNameW[MAX_PATH]; ANSI_STRING FileName;
i = 0; WINBOOL Result;
while ((*lpFileName)!=0 && i < MAX_PATH)
{ RtlInitAnsiString (&FileName,
FileNameW[i] = *lpFileName; (LPSTR)lpFileName);
lpFileName++;
i++; /* convert ansi (or oem) string to unicode */
} if (bIsFileApiAnsi)
FileNameW[i] = 0; RtlAnsiStringToUnicodeString (&FileNameU,
return SetFileAttributesW(FileNameW, dwFileAttributes); &FileName,
TRUE);
else
RtlOemStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
Result = SetFileAttributesW (FileNameU.Buffer,
dwFileAttributes);
RtlFreeHeap (RtlGetProcessHeap (),
0,
FileNameU.Buffer);
return Result;
} }
@ -598,3 +662,5 @@ WINBOOL STDCALL SetEndOfFile(HANDLE hFile)
DWORD Num; DWORD Num;
return WriteFile(hFile,&x,1,&Num,NULL); return WriteFile(hFile,&x,1,&Num,NULL);
} }
/* EOF */

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.30 2000/02/13 16:05:12 dwelch Exp $ # $Id: makefile,v 1.31 2000/03/15 18:28:34 ekohl Exp $
# #
# ReactOS Operating System # ReactOS Operating System
# #
@ -63,7 +63,7 @@ PROCESS_OBJECTS = process/proc.o process/cmdline.o process/create.o \
STRING_OBJECTS = string/lstring.o STRING_OBJECTS = string/lstring.o
INTERNAL_OBJECTS = internal/dprintf.o internal/string.o INTERNAL_OBJECTS = internal/dprintf.o
EXCEPT_OBJECTS = except/except.o EXCEPT_OBJECTS = except/except.o

View file

@ -1,4 +1,4 @@
/* $Id: section.c,v 1.9 2000/01/11 17:31:22 ekohl Exp $ /* $Id: section.c,v 1.10 2000/03/15 18:30:14 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -55,6 +55,7 @@ HANDLE STDCALL CreateFileMappingA (
flProtect, flProtect,
0, 0,
hFile); hFile);
RtlFreeUnicodeString (&UnicodeName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
@ -163,14 +164,12 @@ LPVOID STDCALL MapViewOfFileEx(HANDLE hFileMappingObject,
ViewShare, ViewShare,
0, 0,
Protect); Protect);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
return NULL; return NULL;
} }
return BaseAddress; return BaseAddress;
} }
@ -231,7 +230,6 @@ OpenFileMappingA (
RtlInitAnsiString(&AnsiName, (LPSTR)lpName); RtlInitAnsiString(&AnsiName, (LPSTR)lpName);
RtlAnsiStringToUnicodeString(&UnicodeName, &AnsiName, TRUE); RtlAnsiStringToUnicodeString(&UnicodeName, &AnsiName, TRUE);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&UnicodeName, &UnicodeName,
Attributes, Attributes,
@ -241,11 +239,12 @@ OpenFileMappingA (
SECTION_ALL_ACCESS, SECTION_ALL_ACCESS,
&ObjectAttributes &ObjectAttributes
); );
RtlFreeUnicodeString (&UnicodeName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
return NULL; return NULL;
} }
return SectionHandle; return SectionHandle;
} }

View file

@ -6,81 +6,99 @@
#include <ntdll/ldr.h> #include <ntdll/ldr.h>
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
HRSRC HRSRC
STDCALL STDCALL
FindResourceA( FindResourceA (
HINSTANCE hModule, HINSTANCE hModule,
LPCSTR lpName, LPCSTR lpName,
LPCSTR lpType LPCSTR lpType
) )
{ {
return FindResourceExA(hModule,lpName,lpType,0); return FindResourceExA (hModule, lpName, lpType, 0);
} }
HRSRC HRSRC
STDCALL STDCALL
FindResourceExA( FindResourceExA(
HINSTANCE hModule, HINSTANCE hModule,
LPCSTR lpType, LPCSTR lpType,
LPCSTR lpName, LPCSTR lpName,
WORD wLanguage WORD wLanguage
) )
{ {
WCHAR ResourceNameW[MAX_PATH]; // WCHAR ResourceNameW[MAX_PATH];
WCHAR TypeNameW[MAX_PATH]; // WCHAR TypeNameW[MAX_PATH];
WCHAR *ResourceName = ResourceNameW; // WCHAR *ResourceName = ResourceNameW;
WCHAR *TypeName = TypeNameW; // WCHAR *TypeName = TypeNameW;
UNICODE_STRING TypeU;
UNICODE_STRING NameU;
ANSI_STRING Type;
ANSI_STRING Name;
HRSRC Res;
if ( HIWORD(lpName) != 0 ) { RtlInitUnicodeString (&NameU,
NULL);
RtlInitUnicodeString (&TypeU,
NULL);
if (!KERNEL32_AnsiToUnicode(ResourceNameW, if (HIWORD(lpName) != 0)
lpName, {
MAX_PATH)) RtlInitAnsiString (&Name,
{ (LPSTR)lpName);
return NULL; RtlAnsiStringToUnicodeString (&NameU,
} &Name,
} TRUE);
else }
ResourceName = (WCHAR *)lpName; else
NameU.Buffer = (PWSTR)lpName;
if ( HIWORD(lpType) != 0 ) { if (HIWORD(lpType) != 0)
{
RtlInitAnsiString (&Type,
(LPSTR)lpType);
RtlAnsiStringToUnicodeString (&TypeU,
&Type,
TRUE);
}
else
TypeU.Buffer = (PWSTR)lpType;
if (!KERNEL32_AnsiToUnicode(TypeNameW, Res = FindResourceExW (hModule,
lpType, TypeU.Buffer,
MAX_PATH)) NameU.Buffer,
{ wLanguage);
return NULL;
}
}
else
TypeName = lpType;
return FindResourceExW(hModule,TypeName,ResourceName,wLanguage); if (HIWORD(lpName) != 0)
RtlFreeUnicodeString (&NameU);
if (HIWORD(lpType) != 0)
RtlFreeUnicodeString (&TypeU);
return Res;
} }
HRSRC HRSRC
STDCALL STDCALL
FindResourceW( FindResourceW (
HINSTANCE hModule, HINSTANCE hModule,
LPCWSTR lpName, LPCWSTR lpName,
LPCWSTR lpType LPCWSTR lpType
) )
{ {
return FindResourceExW(hModule,lpName,lpType,0); return FindResourceExW (hModule, lpName, lpType, 0);
} }
HRSRC HRSRC
STDCALL STDCALL
FindResourceExW( FindResourceExW (
HINSTANCE hModule, HINSTANCE hModule,
LPCWSTR lpType, LPCWSTR lpType,
LPCWSTR lpName, LPCWSTR lpName,
WORD wLanguage WORD wLanguage
) )
{ {
IMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry; IMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry;
NTSTATUS Status; NTSTATUS Status;
int i,l; int i,l;
@ -89,7 +107,6 @@ FindResourceExW(
if ( hModule == NULL ) if ( hModule == NULL )
hModule = GetModuleHandle(NULL); hModule = GetModuleHandle(NULL);
if ( HIWORD(lpName) != 0 ) { if ( HIWORD(lpName) != 0 ) {
if ( lpName[0] == L'#' ) { if ( lpName[0] == L'#' ) {
l = lstrlenW(lpName) -1; l = lstrlenW(lpName) -1;
@ -104,8 +121,6 @@ FindResourceExW(
lpName = (LPWSTR)nName; lpName = (LPWSTR)nName;
} }
if ( HIWORD(lpType) != 0 ) { if ( HIWORD(lpType) != 0 ) {
if ( lpType[0] == L'#' ) { if ( lpType[0] == L'#' ) {
@ -116,15 +131,12 @@ FindResourceExW(
if ( i < l - 1 ) if ( i < l - 1 )
nType*= 10; nType*= 10;
} }
} }
else else
return NULL; return NULL;
} }
else else
nType = lpType; nType = lpType;
Status = LdrFindResource_U(hModule,&ResourceDataEntry,lpName, nType,wLanguage); Status = LdrFindResource_U(hModule,&ResourceDataEntry,lpName, nType,wLanguage);
if ( !NT_SUCCESS(Status ) ) { if ( !NT_SUCCESS(Status ) ) {
@ -134,27 +146,27 @@ FindResourceExW(
return ResourceDataEntry; return ResourceDataEntry;
} }
HGLOBAL HGLOBAL
STDCALL STDCALL
LoadResource( LoadResource (
HINSTANCE hModule, HINSTANCE hModule,
HRSRC hResInfo HRSRC hResInfo
) )
{ {
void **Data; void **Data;
Data = HeapAlloc(GetProcessHeap(),0,sizeof(void *));
LdrAccessResource(hModule, hResInfo, Data); Data = HeapAlloc (GetProcessHeap (), 0, sizeof(void *));
LdrAccessResource (hModule, hResInfo, Data);
return *Data; return *Data;
} }
DWORD DWORD
STDCALL STDCALL
SizeofResource( SizeofResource (
HINSTANCE hModule, HINSTANCE hModule,
HRSRC hResInfo HRSRC hResInfo
) )
{ {
return ((PIMAGE_RESOURCE_DATA_ENTRY)hResInfo)->Size; return ((PIMAGE_RESOURCE_DATA_ENTRY)hResInfo)->Size;
} }
@ -165,7 +177,7 @@ FreeResource (
HGLOBAL hResData HGLOBAL hResData
) )
{ {
HeapFree(GetProcessHeap(),0,&hResData); HeapFree (GetProcessHeap (), 0, &hResData);
return TRUE; return TRUE;
} }
@ -178,5 +190,4 @@ LockResource (
return hResData; return hResData;
} }
/* EOF */