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,140 +27,140 @@
/* 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
STDCALL
CreateDirectoryExA (
LPCSTR lpTemplateDirectory,
LPCSTR lpNewDirectory, LPCSTR lpNewDirectory,
LPSECURITY_ATTRIBUTES lpSecurityAttributes) 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; RtlInitAnsiString (&TmplDir,
while ((*lpNewDirectory)!=0 && i < MAX_PATH) (LPSTR)lpTemplateDirectory);
{
NewDirectoryW[i] = *lpNewDirectory;
lpNewDirectory++;
i++;
}
NewDirectoryW[i] = 0;
}
DPRINT ("\n");
return CreateDirectoryExW(lpTemplateDirectory?TemplateDirectoryW:NULL, /* convert ansi (or oem) string to unicode */
lpNewDirectory?NewDirectoryW:NULL, if (bIsFileApiAnsi)
RtlAnsiStringToUnicodeString (&TmplDirU,
&TmplDir,
TRUE);
else
RtlOemStringToUnicodeString (&TmplDirU,
&TmplDir,
TRUE);
}
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
CreateDirectoryW (
LPCWSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{
return CreateDirectoryExW (NULL,
lpPathName,
lpSecurityAttributes); lpSecurityAttributes);
} }
WINBOOL STDCALL CreateDirectoryW(LPCWSTR lpPathName, WINBOOL
LPSECURITY_ATTRIBUTES lpSecurityAttributes) STDCALL
{ CreateDirectoryExW (
return CreateDirectoryExW(NULL,lpPathName,lpSecurityAttributes); LPCWSTR lpTemplateDirectory,
}
WINBOOL STDCALL CreateDirectoryExW(LPCWSTR lpTemplateDirectory,
LPCWSTR lpNewDirectory, LPCWSTR lpNewDirectory,
LPSECURITY_ATTRIBUTES lpSecurityAttributes) LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{ {
NTSTATUS errCode;
HANDLE DirectoryHandle;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DirectoryNameString;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
WCHAR PathNameW[MAX_PATH]; UNICODE_STRING NtPathU;
WCHAR DirectoryNameW[MAX_PATH]; HANDLE DirectoryHandle;
UINT Len = 0; NTSTATUS Status;
DPRINT("lpTemplateDirectory %S lpNewDirectory %S lpSecurityAttributes %p\n", DPRINT ("lpTemplateDirectory %S lpNewDirectory %S lpSecurityAttributes %p\n",
lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes); lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes);
if ( lpTemplateDirectory != NULL && *lpTemplateDirectory != 0 ) if (lpTemplateDirectory != NULL && *lpTemplateDirectory != 0)
{ {
// get object attributes from template directory // get object attributes from template directory
DPRINT("KERNEL32:FIXME:%s:%d\n",__FILE__,__LINE__); 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; return FALSE;
if ( PathNameW[Len-1] != L'\\' ) {
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
}
wcscat(PathNameW,lpNewDirectory);
} }
DirectoryNameW[0] = '\\'; if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpNewDirectory,
DirectoryNameW[1] = '?'; &NtPathU,
DirectoryNameW[2] = '?'; NULL,
DirectoryNameW[3] = '\\'; NULL))
DirectoryNameW[4] = 0;
wcscat(DirectoryNameW,PathNameW);
DirectoryNameString.Length = wcslen (DirectoryNameW)*sizeof(WCHAR);
if ( DirectoryNameString.Length == 0 )
return FALSE; return FALSE;
if ( DirectoryNameString.Length > MAX_PATH*sizeof(WCHAR) ) DPRINT1 ("NtPathU \'%wZ\'\n", &NtPathU);
return FALSE;
DirectoryNameString.Buffer = (WCHAR *)DirectoryNameW;
DirectoryNameString.MaximumLength = DirectoryNameString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &DirectoryNameString; ObjectAttributes.ObjectName = &NtPathU;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT; ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL; ObjectAttributes.SecurityQualityOfService = NULL;
errCode = NtCreateFile(&DirectoryHandle, Status = NtCreateFile (&DirectoryHandle,
DIRECTORY_ALL_ACCESS, DIRECTORY_ALL_ACCESS,
&ObjectAttributes, &ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
@ -171,106 +171,88 @@ WINBOOL STDCALL CreateDirectoryExW(LPCWSTR lpTemplateDirectory,
FILE_DIRECTORY_FILE, FILE_DIRECTORY_FILE,
NULL, NULL,
0); 0);
DPRINT("errCode: %x\n", errCode); DPRINT("Status: %lx\n", Status);
if (!NT_SUCCESS(errCode))
RtlFreeHeap (RtlGetProcessHeap (),
0,
NtPathU.Buffer);
if (!NT_SUCCESS(Status))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError(RtlNtStatusToDosError(Status));
return FALSE; return FALSE;
} }
NtClose(DirectoryHandle); NtClose (DirectoryHandle);
return TRUE; return TRUE;
} }
WINBOOL STDCALL RemoveDirectoryA(LPCSTR lpPathName)
WINBOOL
STDCALL
RemoveDirectoryA (
LPCSTR lpPathName
)
{ {
WCHAR PathNameW[MAX_PATH]; UNICODE_STRING PathNameU;
ULONG i; ANSI_STRING PathName;
i = 0; WINBOOL Result;
while ((*lpPathName)!=0 && i < MAX_PATH)
{ RtlInitAnsiString (&PathName,
PathNameW[i] = *lpPathName; (LPSTR)lpPathName);
lpPathName++;
i++; /* convert ansi (or oem) string to unicode */
} if (bIsFileApiAnsi)
PathNameW[i] = 0; RtlAnsiStringToUnicodeString (&PathNameU,
return RemoveDirectoryW(PathNameW); &PathName,
TRUE);
else
RtlOemStringToUnicodeString (&PathNameU,
&PathName,
TRUE);
Result = RemoveDirectoryW (PathNameU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
PathNameU.Buffer);
return Result;
} }
WINBOOL STDCALL RemoveDirectoryW(LPCWSTR lpPathName) WINBOOL
STDCALL
RemoveDirectoryW (
LPCWSTR lpPathName
)
{ {
NTSTATUS errCode;
HANDLE DirectoryHandle;
IO_STATUS_BLOCK IoStatusBlock;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DirectoryNameString;
WCHAR PathNameW[MAX_PATH];
WCHAR DirectoryNameW[MAX_PATH];
FILE_DISPOSITION_INFORMATION FileDispInfo; FILE_DISPOSITION_INFORMATION FileDispInfo;
UINT Len = 0; OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING NtPathU;
HANDLE DirectoryHandle;
NTSTATUS Status;
DPRINT("lpPathName %S\n", DPRINT("lpPathName %S\n", lpPathName);
lpPathName);
if (lpPathName[1] == (WCHAR)':') if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpPathName,
{ &NtPathU,
wcscpy(PathNameW, lpPathName); NULL,
} NULL))
else if (wcslen(lpPathName) > 4 &&
lpPathName[0] == (WCHAR)'\\' &&
lpPathName[1] == (WCHAR)'\\' &&
lpPathName[2] == (WCHAR)'.' &&
lpPathName[3] == (WCHAR)'\\')
{
wcscpy(PathNameW, lpPathName);
}
else if (lpPathName[0] == (WCHAR)'\\')
{
GetCurrentDirectoryW(MAX_PATH,PathNameW);
wcscpy (&PathNameW[2], lpPathName);
}
else
{
Len = GetCurrentDirectoryW(MAX_PATH,PathNameW);
if ( Len == 0 )
return FALSE; return FALSE;
if ( PathNameW[Len-1] != L'\\' ) {
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
}
wcscat(PathNameW,lpPathName);
}
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.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &DirectoryNameString; ObjectAttributes.ObjectName = &NtPathU;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL; ObjectAttributes.SecurityQualityOfService = NULL;
DPRINT("DirectoryNameW '%S'\n", DirectoryNameW); DPRINT("NtPathU '%S'\n", NtPathU.Buffer);
errCode = NtCreateFile(&DirectoryHandle, Status = NtCreateFile (&DirectoryHandle,
FILE_WRITE_ATTRIBUTES, /* 0x110080 */ FILE_WRITE_ATTRIBUTES, /* 0x110080 */
&ObjectAttributes, &ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
@ -282,35 +264,37 @@ WINBOOL STDCALL RemoveDirectoryW(LPCWSTR lpPathName)
NULL, NULL,
0); 0);
if (!NT_SUCCESS(errCode)) RtlFreeHeap (RtlGetProcessHeap (),
0,
NtPathU.Buffer);
if (!NT_SUCCESS(Status))
{ {
CHECKPOINT; CHECKPOINT;
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError (RtlNtStatusToDosError (Status));
return FALSE; return FALSE;
} }
FileDispInfo.DeleteFile = TRUE; FileDispInfo.DeleteFile = TRUE;
errCode = NtSetInformationFile(DirectoryHandle, Status = NtSetInformationFile (DirectoryHandle,
&IoStatusBlock, &IoStatusBlock,
&FileDispInfo, &FileDispInfo,
sizeof(FILE_DISPOSITION_INFORMATION), sizeof(FILE_DISPOSITION_INFORMATION),
FileDispositionInformation); FileDispositionInformation);
if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(errCode))
{ {
CHECKPOINT; CHECKPOINT;
NtClose(DirectoryHandle); NtClose(DirectoryHandle);
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError (RtlNtStatusToDosError (Status));
return FALSE; return FALSE;
} }
errCode = NtClose(DirectoryHandle); Status = NtClose (DirectoryHandle);
if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(errCode))
{ {
CHECKPOINT; CHECKPOINT;
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError (RtlNtStatusToDosError (Status));
return FALSE; return FALSE;
} }
@ -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) */
if (bIsFileApiAnsi)
RtlUnicodeStringToAnsiString (&FullName, RtlUnicodeStringToAnsiString (&FullName,
&FullNameU, &FullNameU,
FALSE); FALSE);
else
RtlUnicodeStringToOemString (&FullName,
&FullNameU,
FALSE);
if (lpFilePart != NULL) if (lpFilePart != NULL)
{ {
@ -424,7 +397,7 @@ GetFullPathNameW (
DWORD DWORD
STDCALL STDCALL
GetShortPathNameA( GetShortPathNameA (
LPCSTR lpszLongPath, LPCSTR lpszLongPath,
LPSTR lpszShortPath, LPSTR lpszShortPath,
DWORD cchBuffer DWORD cchBuffer
@ -441,22 +414,25 @@ 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,
@ -465,57 +441,107 @@ SearchPathA(
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,
DWORD
STDCALL
SearchPathW (
LPCWSTR lpPath,
LPCWSTR lpFileName, LPCWSTR lpFileName,
LPCWSTR lpExtension, LPCWSTR lpExtension,
DWORD nBufferLength, DWORD nBufferLength,
LPWSTR lpBuffer, LPWSTR lpBuffer,
LPWSTR *lpFilePart) LPWSTR *lpFilePart
)
/* /*
* FUNCTION: Searches for the specified file * FUNCTION: Searches for the specified file
* ARGUMENTS: * ARGUMENTS:

View file

@ -29,37 +29,53 @@ 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
STDCALL
OpenFile (
LPCSTR lpFileName,
LPOFSTRUCT lpReOpenBuff, LPOFSTRUCT lpReOpenBuff,
UINT uStyle) UINT uStyle
)
{ {
NTSTATUS errCode;
HANDLE FileHandle = NULL;
UNICODE_STRING FileNameString;
WCHAR FileNameW[MAX_PATH];
WCHAR PathNameW[MAX_PATH];
ULONG i;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
WCHAR *FilePart; UNICODE_STRING FileNameString;
UNICODE_STRING FileNameU;
ANSI_STRING FileName;
WCHAR PathNameW[MAX_PATH];
HANDLE FileHandle = NULL;
NTSTATUS errCode;
PWCHAR FilePart;
ULONG Len; ULONG Len;
if (lpReOpenBuff == NULL) if (lpReOpenBuff == NULL)
@ -67,25 +83,39 @@ HFILE STDCALL OpenFile(LPCSTR lpFileName,
return FALSE; return FALSE;
} }
i = 0; RtlInitAnsiString (&FileName,
while ((*lpFileName)!=0 && i < MAX_PATH) (LPSTR)lpFileName);
{
FileNameW[i] = *lpFileName;
lpFileName++;
i++;
}
FileNameW[i] = 0;
Len = SearchPathW(NULL,FileNameW,NULL,MAX_PATH,PathNameW,&FilePart); /* convert ansi (or oem) string to unicode */
if ( Len == 0 ) if (bIsFileApiAnsi)
RtlAnsiStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
else
RtlOemStringToUnicodeString (&FileNameU,
&FileName,
TRUE);
Len = SearchPathW (NULL,
FileNameU.Buffer,
NULL,
MAX_PATH,
PathNameW,
&FilePart);
RtlFreeHeap (RtlGetProcessHeap (),
0,
FileNameU.Buffer);
if (Len == 0)
return (HFILE)NULL; return (HFILE)NULL;
if ( Len > MAX_PATH ) if (Len > MAX_PATH)
return (HFILE)NULL; return (HFILE)NULL;
FileNameString.Length = lstrlenW(PathNameW)*sizeof(WCHAR); FileNameString.Length = lstrlenW(PathNameW) * sizeof(WCHAR);
FileNameString.Buffer = PathNameW; FileNameString.Buffer = PathNameW;
FileNameString.MaximumLength = FileNameString.Length+sizeof(WCHAR); FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
@ -97,10 +127,10 @@ HFILE STDCALL OpenFile(LPCSTR lpFileName,
// FILE_SHARE_READ // FILE_SHARE_READ
// FILE_NO_INTERMEDIATE_BUFFERING // FILE_NO_INTERMEDIATE_BUFFERING
if ((uStyle & OF_PARSE) == OF_PARSE ) if ((uStyle & OF_PARSE) == OF_PARSE)
return (HFILE)NULL; return (HFILE)NULL;
errCode = NtOpenFile(&FileHandle, errCode = NtOpenFile (&FileHandle,
GENERIC_READ|SYNCHRONIZE, GENERIC_READ|SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
@ -111,7 +141,7 @@ HFILE STDCALL OpenFile(LPCSTR lpFileName,
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError (RtlNtStatusToDosError (errCode));
return (HFILE)INVALID_HANDLE_VALUE; return (HFILE)INVALID_HANDLE_VALUE;
} }
@ -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; RtlInitAnsiString (&FileName,
while ((*lpFileName)!=0 && i < MAX_PATH) (LPSTR)lpFileName);
{
FileNameW[i] = *lpFileName; /* convert ansi (or oem) string to unicode */
lpFileName++; if (bIsFileApiAnsi)
i++; RtlAnsiStringToUnicodeString (&FileNameU,
} &FileName,
FileNameW[i] = 0; TRUE);
return GetFileAttributesW(FileNameW); 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));
@ -164,8 +165,6 @@ LPVOID STDCALL MapViewOfFileEx(HANDLE hFileMappingObject,
0, 0,
Protect); Protect);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
@ -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,6 +239,7 @@ 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));

View file

@ -6,15 +6,16 @@
#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
@ -26,61 +27,78 @@ FindResourceExA(
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))
{ {
return NULL; RtlInitAnsiString (&Name,
} (LPSTR)lpName);
RtlAnsiStringToUnicodeString (&NameU,
&Name,
TRUE);
} }
else else
ResourceName = (WCHAR *)lpName; NameU.Buffer = (PWSTR)lpName;
if ( HIWORD(lpType) != 0 ) { if (HIWORD(lpType) != 0)
if (!KERNEL32_AnsiToUnicode(TypeNameW,
lpType,
MAX_PATH))
{ {
return NULL; RtlInitAnsiString (&Type,
} (LPSTR)lpType);
RtlAnsiStringToUnicodeString (&TypeU,
&Type,
TRUE);
} }
else else
TypeName = lpType; TypeU.Buffer = (PWSTR)lpType;
return FindResourceExW(hModule,TypeName,ResourceName,wLanguage); Res = FindResourceExW (hModule,
TypeU.Buffer,
NameU.Buffer,
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;
@ -105,8 +122,6 @@ FindResourceExW(
lpName = (LPWSTR)nName; lpName = (LPWSTR)nName;
} }
if ( HIWORD(lpType) != 0 ) { if ( HIWORD(lpType) != 0 ) {
if ( lpType[0] == L'#' ) { if ( lpType[0] == L'#' ) {
l = lstrlenW(lpType); l = lstrlenW(lpType);
@ -116,7 +131,6 @@ FindResourceExW(
if ( i < l - 1 ) if ( i < l - 1 )
nType*= 10; nType*= 10;
} }
} }
else else
return NULL; return NULL;
@ -124,8 +138,6 @@ FindResourceExW(
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 ) ) {
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
@ -134,24 +146,24 @@ 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
) )
@ -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 */