diff options
Diffstat (limited to '')
-rw-r--r-- | private/mvdm/oemuni/file.c | 1138 | ||||
-rw-r--r-- | private/mvdm/oemuni/makefile | 9 | ||||
-rw-r--r-- | private/mvdm/oemuni/oem.h | 7 | ||||
-rw-r--r-- | private/mvdm/oemuni/process.c | 916 | ||||
-rw-r--r-- | private/mvdm/oemuni/sources | 45 | ||||
-rw-r--r-- | private/mvdm/oemuni/toemuni.c | 184 |
6 files changed, 2299 insertions, 0 deletions
diff --git a/private/mvdm/oemuni/file.c b/private/mvdm/oemuni/file.c new file mode 100644 index 000000000..8c5910439 --- /dev/null +++ b/private/mvdm/oemuni/file.c @@ -0,0 +1,1138 @@ +/* file.c + * OemUnicode win32 thunks + * - file and debug apis + * + * 14-Jan-1993 Jonle + */ +#include <nt.h> +#include <ntrtl.h> +#include <nturtl.h> +#include <windows.h> +#include <oemuni.h> +#include "oem.h" + + + +BOOL +CheckForSameCurdir( + PUNICODE_STRING PathName + ) +{ + PCURDIR CurDir; + UNICODE_STRING CurrentDir; + BOOL rv; + + + CurDir = &(NtCurrentPeb()->ProcessParameters->CurrentDirectory); + + if (CurDir->DosPath.Length > 6 ) { + if ( (CurDir->DosPath.Length-2) != PathName->Length ) { + return FALSE; + } + } + else { + if ( CurDir->DosPath.Length != PathName->Length ) { + return FALSE; + } + } + + RtlAcquirePebLock(); + + CurrentDir = CurDir->DosPath; + if ( CurrentDir.Length > 6 ) { + CurrentDir.Length -= 2; + } + rv = FALSE; + + if ( RtlEqualUnicodeString(&CurrentDir,PathName,TRUE) ) { + rv = TRUE; + } + RtlReleasePebLock(); + + return rv; +} + + + +HANDLE +WINAPI +CreateFileOem( + LPCSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile + ) + +/*++ + +Routine Description: + + OEM thunk to CreateFileW + +--*/ + +{ + + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + HANDLE hFile; + DWORD dw; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return INVALID_HANDLE_VALUE; + } + + + /* + * Dos allows change of attributes (time\date etc) + * on files opend for generic read, so we add + * FILE_WRITE_ATTRIBUTES to the Desired access. + */ + hFile = CreateFileW( Unicode->Buffer, + dwDesiredAccess == GENERIC_READ + ? dwDesiredAccess | FILE_WRITE_ATTRIBUTES + : dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile + ); + + + /* + * However, NT may fail the request because of the + * extra FILE_WRITE_ATTRIBUTES. Common example + * is a generic read open on a read only net share. + * Retry the Createfile without FILE_WRTIE_ATTRIBUTES + */ + if (hFile == INVALID_HANDLE_VALUE && dwDesiredAccess == GENERIC_READ) + { + hFile = CreateFileW( Unicode->Buffer, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile + ); + } + + return hFile; +} + + + +BOOL +APIENTRY +SetFileAttributesOem( + LPSTR lpFileName, + DWORD dwFileAttributes + ) + +/*++ + +Routine Description: + + Oem thunk to SetFileAttributesW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + return ( SetFileAttributesW( + Unicode->Buffer, + dwFileAttributes + ) + ); +} + + + +DWORD +APIENTRY +GetFileAttributesOem( + LPSTR lpFileName + ) + +/*++ + +Routine Description: + + OEM thunk to GetFileAttributesW + +--*/ + +{ + + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + RtlInitAnsiString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0xFFFFFFFF; + } + return ( GetFileAttributesW(Unicode->Buffer) ); +} + + + +BOOL +APIENTRY +DeleteFileOem( + LPSTR lpFileName + ) + +/*++ + +Routine Description: + + Oem thunk to DeleteFileW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + return ( DeleteFileW(Unicode->Buffer) ); +} + + + + +BOOL +APIENTRY +MoveFileOem( + LPSTR lpExistingFileName, + LPSTR lpNewFileName + ) + +/*++ + +Routine Description: + + OEM thunk to MoveFileW + +--*/ + +{ + + PUNICODE_STRING Unicode; + UNICODE_STRING UnicodeNewFileName; + OEM_STRING OemString; + NTSTATUS Status; + BOOL ReturnValue; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpExistingFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + + if (ARGUMENT_PRESENT( lpNewFileName )) { + InitOemString(&OemString,lpNewFileName); + Status = RtlOemStringToUnicodeString(&UnicodeNewFileName,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + else { + UnicodeNewFileName.Buffer = NULL; + } + + ReturnValue = MoveFileExW(Unicode->Buffer, + UnicodeNewFileName.Buffer, + MOVEFILE_COPY_ALLOWED); + + if (UnicodeNewFileName.Buffer != NULL) { + RtlFreeUnicodeString(&UnicodeNewFileName); + } + + return ReturnValue; +} + + +BOOL +APIENTRY +MoveFileExOem( + LPSTR lpExistingFileName, + LPSTR lpNewFileName, + DWORD fdwFlags + ) + +/*++ + +Routine Description: + + OEM thunk to MoveFileExW + +--*/ + +{ + + PUNICODE_STRING Unicode; + UNICODE_STRING UnicodeNewFileName; + OEM_STRING OemString; + NTSTATUS Status; + BOOL ReturnValue; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpExistingFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + + if (ARGUMENT_PRESENT( lpNewFileName )) { + InitOemString(&OemString,lpNewFileName); + Status = RtlOemStringToUnicodeString(&UnicodeNewFileName,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + else { + UnicodeNewFileName.Buffer = NULL; + } + + ReturnValue = MoveFileExW(Unicode->Buffer, + UnicodeNewFileName.Buffer, + fdwFlags); + + if (UnicodeNewFileName.Buffer != NULL) { + RtlFreeUnicodeString(&UnicodeNewFileName); + } + + return ReturnValue; +} + + +HANDLE +APIENTRY +FindFirstFileOem( + LPSTR lpFileName, + LPWIN32_FIND_DATAA lpFindFileData + ) + +/*++ + +Routine Description: + + OEM thunk to FindFirstFileW + +--*/ + +{ + HANDLE ReturnValue; + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + UNICODE_STRING UnicodeString; + WIN32_FIND_DATAW FindFileData; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return INVALID_HANDLE_VALUE; + } + ReturnValue = FindFirstFileW(Unicode->Buffer,&FindFileData); + if ( ReturnValue == INVALID_HANDLE_VALUE ) { + return ReturnValue; + } + RtlMoveMemory( + lpFindFileData, + &FindFileData, + (ULONG)((ULONG)&FindFileData.cFileName[0] - (ULONG)&FindFileData) + ); + RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cFileName); + OemString.Buffer = lpFindFileData->cFileName; + OemString.MaximumLength = MAX_PATH; + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE); + if (NT_SUCCESS(Status)) { + RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cAlternateFileName); + OemString.Buffer = lpFindFileData->cAlternateFileName; + OemString.MaximumLength = 14; + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE); + } + if ( !NT_SUCCESS(Status) ) { + FindClose(ReturnValue); + BaseSetLastNTError(Status); + return INVALID_HANDLE_VALUE; + } + return ReturnValue; +} + + + + +BOOL +APIENTRY +FindNextFileOem( + HANDLE hFindFile, + LPWIN32_FIND_DATAA lpFindFileData + ) + +/*++ + +Routine Description: + + Oem thunk to FindFileDataW + +--*/ + +{ + + BOOL ReturnValue; + OEM_STRING OemString; + NTSTATUS Status; + UNICODE_STRING UnicodeString; + WIN32_FIND_DATAW FindFileData; + + ReturnValue = FindNextFileW(hFindFile,&FindFileData); + if ( !ReturnValue ) { + return ReturnValue; + } + RtlMoveMemory( + lpFindFileData, + &FindFileData, + (ULONG)((ULONG)&FindFileData.cFileName[0] - (ULONG)&FindFileData) + ); + RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cFileName); + OemString.Buffer = lpFindFileData->cFileName; + OemString.MaximumLength = MAX_PATH; + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE); + if (NT_SUCCESS(Status)) { + RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cAlternateFileName); + OemString.Buffer = lpFindFileData->cAlternateFileName; + OemString.MaximumLength = 14; + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE); + } + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + return ReturnValue; +} + + + + +DWORD +APIENTRY +GetFullPathNameOem( + LPCSTR lpFileName, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart + ) + +/*++ + +Routine Description: + + Oem thunk to GetFullPathNameW + +--*/ + +{ + + NTSTATUS Status; + ULONG UnicodeLength; + UNICODE_STRING UnicodeString; + UNICODE_STRING UnicodeResult; + OEM_STRING OemString; + OEM_STRING OemResult; + PWSTR Ubuff; + PWSTR FilePart; + PWSTR *FilePartPtr; + + if ( ARGUMENT_PRESENT(lpFilePart) ) { + FilePartPtr = &FilePart; + } + else { + FilePartPtr = NULL; + } + + RtlInitString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(&UnicodeString,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ){ + RtlFreeUnicodeString(&UnicodeString); + BaseSetLastNTError(Status); + return 0; + } + + Ubuff = RtlAllocateHeap(RtlProcessHeap(), 0,(MAX_PATH<<1) + sizeof(UNICODE_NULL)); + if ( !Ubuff ) { + RtlFreeUnicodeString(&UnicodeString); + BaseSetLastNTError(STATUS_NO_MEMORY); + return 0; + } + + UnicodeLength = RtlGetFullPathName_U( + UnicodeString.Buffer, + (MAX_PATH<<1), + Ubuff, + FilePartPtr + ); + UnicodeLength >>= 1; + if ( UnicodeLength && UnicodeLength < nBufferLength ) { + RtlInitUnicodeString(&UnicodeResult,Ubuff); + Status = RtlUnicodeStringToOemString(&OemResult,&UnicodeResult,TRUE); + if ( NT_SUCCESS(Status) ) { + RtlMoveMemory(lpBuffer,OemResult.Buffer,UnicodeLength+1); + RtlFreeOemString(&OemResult); + + if ( ARGUMENT_PRESENT(lpFilePart) ) { + if ( FilePart == NULL ) { + *lpFilePart = NULL; + } + else { + *lpFilePart = (PSZ)(FilePart - Ubuff); + *lpFilePart = *lpFilePart + (ULONG)lpBuffer; + } + } + } + else { + BaseSetLastNTError(Status); + UnicodeLength = 0; + } + } + else { + if ( UnicodeLength ) { + UnicodeLength++; + } + } + RtlFreeUnicodeString(&UnicodeString); + RtlFreeHeap(RtlProcessHeap(), 0,Ubuff); + + return (DWORD)UnicodeLength; +} + + +DWORD +APIENTRY +GetCurrentDirectoryOem( + DWORD nBufferLength, + LPSTR lpBuffer + ) + +/*++ + +Routine Description: + + Oem thunk to GetCurrentDirectoryW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + DWORD ReturnValue; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + Unicode->Length = (USHORT)RtlGetCurrentDirectory_U( + Unicode->MaximumLength, + Unicode->Buffer + ); + + if ( nBufferLength > (DWORD)(Unicode->Length>>1) ) { + OemString.Buffer = lpBuffer; + OemString.MaximumLength = (USHORT)(nBufferLength+1); + Status = RtlUnicodeStringToOemString(&OemString,Unicode,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnValue = 0; + } + else { + ReturnValue = OemString.Length; + } + } + else { + ReturnValue = ((Unicode->Length)>>1)+1; + } + return ReturnValue; +} + + + + + +BOOL +APIENTRY +SetCurrentDirectoryOem( + LPSTR lpPathName + ) + +/*++ + +Routine Description: + + Oem thunk to SetCurrentDirectoryW + +--*/ + +{ + + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpPathName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + + if (!CheckForSameCurdir(Unicode)) { + Status = RtlSetCurrentDirectory_U(Unicode); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + + return TRUE; +} + + +BOOL +APIENTRY +CreateDirectoryOem( + LPSTR lpPathName, + LPSECURITY_ATTRIBUTES lpSecurityAttributes + ) + +/*++ + +Routine Description: + + Oem thunk to CreateDirectoryW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpPathName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + return ( CreateDirectoryW(Unicode->Buffer,lpSecurityAttributes) ); +} + + + +BOOL +APIENTRY +RemoveDirectoryOem( + LPSTR lpPathName + ) + +/*++ + +Routine Description: + + Oem thunk to RemoveDirectoryW + +--*/ + +{ + + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpPathName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + return ( RemoveDirectoryW(Unicode->Buffer) ); +} + + + + + +UINT +APIENTRY +GetDriveTypeOem( + LPSTR lpRootPathName + ) + +/*++ + +Routine Description: + + OEM thunk to GetDriveTypeW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString( + &OemString, + ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\" + ); + + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 1; + } + return (GetDriveTypeW(Unicode->Buffer)); +} + + + + +BOOL +APIENTRY +GetDiskFreeSpaceOem( + LPSTR lpRootPathName, + LPDWORD lpSectorsPerCluster, + LPDWORD lpBytesPerSector, + LPDWORD lpNumberOfFreeClusters, + LPDWORD lpTotalNumberOfClusters + ) + +/*++ + +Routine Description: + + Oem thunk to GetDiskFreeSpaceW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString( + &OemString, + ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\" + ); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + return ( GetDiskFreeSpaceW( + Unicode->Buffer, + lpSectorsPerCluster, + lpBytesPerSector, + lpNumberOfFreeClusters, + lpTotalNumberOfClusters + ) + ); +} + + + +BOOL +APIENTRY +GetVolumeInformationOem( + LPSTR lpRootPathName, + LPSTR lpVolumeNameBuffer, + DWORD nVolumeNameSize, + LPDWORD lpVolumeSerialNumber, + LPDWORD lpMaximumComponentLength, + LPDWORD lpFileSystemFlags, + LPSTR lpFileSystemNameBuffer, + DWORD nFileSystemNameSize + ) + +/*++ + +Routine Description: + + Oem thunk to GetVolumeInformationW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + UNICODE_STRING UnicodeVolumeName; + UNICODE_STRING UnicodeFileSystemName; + OEM_STRING OemVolumeName; + OEM_STRING OemFileSystemName; + BOOL ReturnValue; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString( + &OemString, + ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\" + ); + + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + + UnicodeVolumeName.Buffer = NULL; + UnicodeFileSystemName.Buffer = NULL; + UnicodeVolumeName.MaximumLength = 0; + UnicodeFileSystemName.MaximumLength = 0; + OemVolumeName.Buffer = lpVolumeNameBuffer; + OemVolumeName.MaximumLength = (USHORT)(nVolumeNameSize+1); + OemFileSystemName.Buffer = lpFileSystemNameBuffer; + OemFileSystemName.MaximumLength = (USHORT)(nFileSystemNameSize+1); + + try { + if ( ARGUMENT_PRESENT(lpVolumeNameBuffer) ) { + UnicodeVolumeName.MaximumLength = OemVolumeName.MaximumLength << 1; + UnicodeVolumeName.Buffer = RtlAllocateHeap( + RtlProcessHeap(), 0, + UnicodeVolumeName.MaximumLength + ); + + if ( !UnicodeVolumeName.Buffer ) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + } + + if ( ARGUMENT_PRESENT(lpFileSystemNameBuffer) ) { + UnicodeFileSystemName.MaximumLength = OemFileSystemName.MaximumLength << 1; + UnicodeFileSystemName.Buffer = RtlAllocateHeap( + RtlProcessHeap(), 0, + UnicodeFileSystemName.MaximumLength + ); + + if ( !UnicodeFileSystemName.Buffer ) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + } + + ReturnValue = GetVolumeInformationW( + Unicode->Buffer, + UnicodeVolumeName.Buffer, + nVolumeNameSize, + lpVolumeSerialNumber, + lpMaximumComponentLength, + lpFileSystemFlags, + UnicodeFileSystemName.Buffer, + nFileSystemNameSize + ); + + if ( ReturnValue ) { + + if ( ARGUMENT_PRESENT(lpVolumeNameBuffer) ) { + RtlInitUnicodeString( + &UnicodeVolumeName, + UnicodeVolumeName.Buffer + ); + + Status = RtlUnicodeStringToOemString( + &OemVolumeName, + &UnicodeVolumeName, + FALSE + ); + + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + + if ( ARGUMENT_PRESENT(lpFileSystemNameBuffer) ) { + RtlInitUnicodeString( + &UnicodeFileSystemName, + UnicodeFileSystemName.Buffer + ); + + Status = RtlUnicodeStringToOemString( + &OemFileSystemName, + &UnicodeFileSystemName, + FALSE + ); + + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + } + } + finally { + if ( UnicodeVolumeName.Buffer ) { + RtlFreeHeap(RtlProcessHeap(), 0,UnicodeVolumeName.Buffer); + } + if ( UnicodeFileSystemName.Buffer ) { + RtlFreeHeap(RtlProcessHeap(), 0,UnicodeFileSystemName.Buffer); + } + } + + return ReturnValue; +} + + + + + + +VOID +APIENTRY +OutputDebugStringOem( + LPCSTR lpOutputString + ) + +/*++ + +Routine Description: + + OEM thunk to OutputDebugStringA + +--*/ + +{ + UNICODE_STRING Unicode; + OEM_STRING OemString; + ANSI_STRING AnsiString; + NTSTATUS Status; + + + Unicode.Buffer = NULL; + AnsiString.Buffer = NULL; + try { + InitOemString(&OemString, lpOutputString); + Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE); + if ( !NT_SUCCESS(Status) ) { + goto try_exit; + } + + Status = RtlUnicodeStringToAnsiString(&AnsiString,&Unicode,TRUE); + if ( !NT_SUCCESS(Status) ) { + goto try_exit; + } + + OutputDebugStringA(AnsiString.Buffer); + +try_exit:; + } + finally { + if (Unicode.Buffer != NULL) { + RtlFreeUnicodeString( &Unicode ); + } + if (AnsiString.Buffer != NULL) { + RtlFreeAnsiString( &AnsiString); + } + } +} + +BOOL +APIENTRY +GetComputerNameOem( + LPSTR lpBuffer, + LPDWORD nSize + ) + +/*++ + +Routine Description: + + Oem thunk to GetComputerNameW + +--*/ + +{ + UNICODE_STRING UnicodeString; + OEM_STRING OemString; + LPWSTR UnicodeBuffer; + + // + // Work buffer needs to be twice the size of the user's buffer + // + + UnicodeBuffer = RtlAllocateHeap(RtlProcessHeap(), 0, *nSize * sizeof(WCHAR)); + if (!UnicodeBuffer) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return(FALSE); + } + + // + // Set up an ANSI_STRING that points to the user's buffer + // + + OemString.MaximumLength = (USHORT) *nSize; + OemString.Length = 0; + OemString.Buffer = lpBuffer; + + // + // Call the UNICODE version to do the work + // + + if (!GetComputerNameW(UnicodeBuffer, nSize)) { + RtlFreeHeap(RtlProcessHeap(), 0, UnicodeBuffer); + return(FALSE); + } + + // + // Now convert back to Oem for the caller + // + + RtlInitUnicodeString(&UnicodeString, UnicodeBuffer); + RtlUnicodeStringToOemString(&OemString, &UnicodeString, FALSE); + + *nSize = OemString.Length; + RtlFreeHeap(RtlProcessHeap(), 0, UnicodeBuffer); + return(TRUE); + +} + + +BOOL +WINAPI +RemoveFontResourceOem( + LPSTR lpFileName + ) + +/*++ + +Routine Description: + + Oem thunk to RemoveFontResourceW + +--*/ + +{ + PUNICODE_STRING Unicode; + OEM_STRING OemString; + NTSTATUS Status; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpFileName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return FALSE; + } + return ( RemoveFontResourceW(Unicode->Buffer) ); +} diff --git a/private/mvdm/oemuni/makefile b/private/mvdm/oemuni/makefile new file mode 100644 index 000000000..ab08ca0cf --- /dev/null +++ b/private/mvdm/oemuni/makefile @@ -0,0 +1,9 @@ +# DEM makefile +# 01-Apr-1991 Sudeep Bharati Created +# + +# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source +# file to this component. This file merely indirects to the real make file +# that is shared by all the components of NT OS/2 +# +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/private/mvdm/oemuni/oem.h b/private/mvdm/oemuni/oem.h new file mode 100644 index 000000000..9fa59cae0 --- /dev/null +++ b/private/mvdm/oemuni/oem.h @@ -0,0 +1,7 @@ +/* + * private macros for oemuni lib + * 18-Jan-1993 Jonle created + */ + +#define InitOemString(dst,src) RtlInitString((PSTRING) dst, src) +#define BaseSetLastNTError(stat) SetLastError(RtlNtStatusToDosError(stat)) diff --git a/private/mvdm/oemuni/process.c b/private/mvdm/oemuni/process.c new file mode 100644 index 000000000..567c99f50 --- /dev/null +++ b/private/mvdm/oemuni/process.c @@ -0,0 +1,916 @@ +/* process.c + * OemUnicode win32 thunks + * - process\env stuff + * + * 14-Jan-1993 Jonle + */ +#include <nt.h> +#include <ntrtl.h> +#include <nturtl.h> +#include <windows.h> +#include <oemuni.h> +#include "oem.h" +#include <vdmapi.h> +UINT +APIENTRY +GetSystemDirectoryOem( + LPSTR lpBuffer, + UINT uSize + ) + +/*++ + +Routine Description: + + OEM thunk to GetSystemDirectoryW + +--*/ + +{ + OEM_STRING OemString; + UNICODE_STRING Unicode; + NTSTATUS Status; + + Unicode.MaximumLength = (USHORT)((uSize<<1)+sizeof(UNICODE_NULL)); + Unicode.Buffer = RtlAllocateHeap( + RtlProcessHeap(), 0, + Unicode.MaximumLength + ); + if ( !Unicode.Buffer ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + return 0; + } + + Unicode.Length = GetSystemDirectoryW(Unicode.Buffer, + (Unicode.MaximumLength-sizeof(UNICODE_NULL))/2 + )*2; + + if ( Unicode.Length > (USHORT)(Unicode.MaximumLength-sizeof(UNICODE_NULL)) ) { + RtlFreeHeap(RtlProcessHeap(), 0,Unicode.Buffer); + return Unicode.Length>>1; + } + OemString.Buffer = lpBuffer; + OemString.MaximumLength = (USHORT)(uSize+1); + Status = RtlUnicodeStringToOemString(&OemString,&Unicode,FALSE); + RtlFreeHeap(RtlProcessHeap(), 0,Unicode.Buffer); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return 0; + } + return OemString.Length; +} + + + +UINT +APIENTRY +GetWindowsDirectoryOem( + LPSTR lpBuffer, + UINT uSize + ) + +/*++ + +Routine Description: + + OEM thunk to GetWindowsDirectoryW + +--*/ + +{ + OEM_STRING OemString; + UNICODE_STRING Unicode; + NTSTATUS Status; + + Unicode.MaximumLength = (USHORT)((uSize<<1)+sizeof(UNICODE_NULL)); + Unicode.Buffer = RtlAllocateHeap( + RtlProcessHeap(), 0, + Unicode.MaximumLength + ); + if ( !Unicode.Buffer ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + return 0; + } + + Unicode.Length = GetWindowsDirectoryW(Unicode.Buffer, + (Unicode.MaximumLength-sizeof(UNICODE_NULL))/2 + )*2; + + if ( Unicode.Length > (USHORT)(Unicode.MaximumLength-sizeof(UNICODE_NULL)) ) { + RtlFreeHeap(RtlProcessHeap(), 0,Unicode.Buffer); + return Unicode.Length>>1; + } + OemString.Buffer = lpBuffer; + OemString.MaximumLength = (USHORT)(uSize+1); + Status = RtlUnicodeStringToOemString(&OemString,&Unicode,FALSE); + RtlFreeHeap(RtlProcessHeap(), 0,Unicode.Buffer); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return 0; + } + return OemString.Length; +} + + +DWORD +APIENTRY +SearchPathOem ( + LPCSTR lpPath, + LPCSTR lpFileName, + LPCSTR lpExtension, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart + ) + +/*++ + +Routine Description: + + Oem thunk to SearchPathW + +--*/ + +{ + + UNICODE_STRING xlpPath; + PUNICODE_STRING Unicode; + UNICODE_STRING xlpExtension; + PWSTR xlpBuffer; + DWORD ReturnValue; + OEM_STRING OemString; + UNICODE_STRING UnicodeString; + NTSTATUS Status; + PWSTR FilePart; + PWSTR *FilePartPtr; + + if ( ARGUMENT_PRESENT(lpFilePart) ) { + FilePartPtr = &FilePart; + } + else { + FilePartPtr = NULL; + } + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + InitOemString(&OemString,lpFileName); + + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0; + } + + if ( ARGUMENT_PRESENT(lpExtension) ) { + InitOemString(&OemString,lpExtension); + Status = RtlOemStringToUnicodeString(&xlpExtension,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return 0; + } + } + else { + xlpExtension.Buffer = NULL; + } + + if ( ARGUMENT_PRESENT(lpPath) ) { + InitOemString(&OemString,lpPath); + Status = RtlOemStringToUnicodeString(&xlpPath,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + if ( ARGUMENT_PRESENT(lpExtension) ) { + RtlFreeUnicodeString(&xlpExtension); + } + BaseSetLastNTError(Status); + return 0; + } + } + else { + xlpPath.Buffer = NULL; + } + + xlpBuffer = RtlAllocateHeap(RtlProcessHeap(), 0,nBufferLength<<1); + if ( !xlpBuffer ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + goto bail0; + } + ReturnValue = SearchPathW( + xlpPath.Buffer, + Unicode->Buffer, + xlpExtension.Buffer, + nBufferLength, + xlpBuffer, + FilePartPtr + ); + if (ReturnValue && ReturnValue <= nBufferLength ) { + RtlInitUnicodeString(&UnicodeString,xlpBuffer); + OemString.MaximumLength = (USHORT)(nBufferLength+1); + OemString.Buffer = lpBuffer; + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnValue = 0; + } + else { + if ( ARGUMENT_PRESENT(lpFilePart) ) { + if ( FilePart == NULL ) { + *lpFilePart = NULL; + } + else { + *lpFilePart = (LPSTR)(FilePart - xlpBuffer); + *lpFilePart = *lpFilePart + (DWORD)lpBuffer; + } + } + } + } + + RtlFreeHeap(RtlProcessHeap(), 0,xlpBuffer); +bail0: + if ( ARGUMENT_PRESENT(lpExtension) ) { + RtlFreeUnicodeString(&xlpExtension); + } + + if ( ARGUMENT_PRESENT(lpPath) ) { + RtlFreeUnicodeString(&xlpPath); + } + return ReturnValue; +} + + +DWORD +APIENTRY +GetTempPathOem( + DWORD nBufferLength, + LPSTR lpBuffer + ) + +/*++ + +Routine Description: + + OEM thunk to GetTempPathW + +--*/ + +{ + OEM_STRING OemString; + UNICODE_STRING UnicodeString; + NTSTATUS Status; + + UnicodeString.MaximumLength = (USHORT)((nBufferLength<<1)+sizeof(UNICODE_NULL)); + UnicodeString.Buffer = RtlAllocateHeap( + RtlProcessHeap(), 0, + UnicodeString.MaximumLength + ); + if ( !UnicodeString.Buffer ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + return 0; + } + UnicodeString.Length = (USHORT)GetTempPathW( + (DWORD)(UnicodeString.MaximumLength-sizeof(UNICODE_NULL))/2, + UnicodeString.Buffer + )*2; + if ( UnicodeString.Length > (USHORT)(UnicodeString.MaximumLength-sizeof(UNICODE_NULL)) ) { + RtlFreeHeap(RtlProcessHeap(), 0,UnicodeString.Buffer); + return UnicodeString.Length>>1; + } + OemString.Buffer = lpBuffer; + OemString.MaximumLength = (USHORT)(nBufferLength+1); + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE); + RtlFreeHeap(RtlProcessHeap(), 0,UnicodeString.Buffer); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return 0; + } + return OemString.Length; +} + + + +UINT +APIENTRY +GetTempFileNameOem( + LPCSTR lpPathName, + LPCSTR lpPrefixString, + UINT uUnique, + LPSTR lpTempFileName + ) + +/*++ + +Routine Description: + + Oem thunk to GetTempFileNameW + +--*/ + +{ + PUNICODE_STRING Unicode; + UNICODE_STRING UnicodePrefix; + OEM_STRING OemString; + NTSTATUS Status; + UINT ReturnValue; + UNICODE_STRING UnicodeResult; + + Unicode = &NtCurrentTeb()->StaticUnicodeString; + + InitOemString(&OemString,lpPathName); + Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0; + } + + InitOemString(&OemString,lpPrefixString); + Status = RtlOemStringToUnicodeString(&UnicodePrefix,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return 0; + } + UnicodeResult.MaximumLength = (USHORT)((MAX_PATH<<1)+sizeof(UNICODE_NULL)); + UnicodeResult.Buffer = RtlAllocateHeap(RtlProcessHeap(), 0,UnicodeResult.MaximumLength); + if ( !UnicodeResult.Buffer ) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + RtlFreeUnicodeString(&UnicodePrefix); + return 0; + } + + ReturnValue = GetTempFileNameW( + Unicode->Buffer, + UnicodePrefix.Buffer, + uUnique, + UnicodeResult.Buffer + ); + if ( ReturnValue ) { + RtlInitUnicodeString(&UnicodeResult,UnicodeResult.Buffer); + OemString.Buffer = lpTempFileName; + OemString.MaximumLength = MAX_PATH+1; + Status = RtlUnicodeStringToOemString(&OemString,&UnicodeResult,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnValue = 0; + } + } + RtlFreeUnicodeString(&UnicodePrefix); + RtlFreeHeap(RtlProcessHeap(), 0,UnicodeResult.Buffer); + + return ReturnValue; +} + + +#if 0 // unused +BOOL +WINAPI +CreateProcessOem( + LPCSTR lpApplicationName, + LPCSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + BOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPSTR lpCurrentDirectory, + LPSTARTUPINFOA lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation + ) + +/*++ + + OEM thunk to CreateProcessW + +--*/ + +{ + NTSTATUS Status; + PUNICODE_STRING CommandLine; + UNICODE_STRING ApplicationName; + UNICODE_STRING CurrentDirectory; + STARTUPINFOW StartupInfo; + OEM_STRING OemString; + UNICODE_STRING Unicode; + UNICODE_STRING DynamicCommandLine; + BOOL ReturnStatus; + + CommandLine = &NtCurrentTeb()->StaticUnicodeString; + + if (ARGUMENT_PRESENT (lpCommandLine)) { + InitOemString(&OemString,lpCommandLine); + if ( OemString.Length<<1 < NtCurrentTeb()->StaticUnicodeString.MaximumLength ) { + DynamicCommandLine.Buffer = NULL; + Status = RtlOemStringToUnicodeString(CommandLine,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + else { + Status = RtlOemStringToUnicodeString(&DynamicCommandLine,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + return FALSE; + } + } + } + else { + DynamicCommandLine.Buffer = NULL; + CommandLine->Buffer = NULL; + } + + ApplicationName.Buffer = NULL; + ApplicationName.Buffer = NULL; + CurrentDirectory.Buffer = NULL; + RtlMoveMemory(&StartupInfo,lpStartupInfo,sizeof(*lpStartupInfo)); + ASSERT(sizeof(StartupInfo) == sizeof(*lpStartupInfo)); + StartupInfo.lpReserved = NULL; + StartupInfo.lpDesktop = NULL; + StartupInfo.lpTitle = NULL; + + try { + if (ARGUMENT_PRESENT(lpApplicationName)) { + InitOemString(&OemString,lpApplicationName); + Status = RtlOemStringToUnicodeString(&ApplicationName,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnStatus = FALSE; + goto tryexit; + } + } + + if (ARGUMENT_PRESENT(lpCurrentDirectory)) { + InitOemString(&OemString,lpCurrentDirectory); + Status = RtlOemStringToUnicodeString(&CurrentDirectory,&OemString,TRUE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnStatus = FALSE; + goto tryexit; + } + } + + if (ARGUMENT_PRESENT(lpStartupInfo->lpReserved)) { + InitOemString(&OemString,lpStartupInfo->lpReserved); + Unicode.MaximumLength = (USHORT)RtlOemStringToUnicodeSize(&OemString) ; + StartupInfo.lpReserved = RtlAllocateHeap(RtlProcessHeap(), 0, Unicode.MaximumLength); + if ( !StartupInfo.lpReserved ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + ReturnStatus = FALSE; + goto tryexit; + } + Unicode.Buffer = StartupInfo.lpReserved; + Status = RtlOemStringToUnicodeString(&Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnStatus = FALSE; + goto tryexit; + } + } + + if (ARGUMENT_PRESENT(lpStartupInfo->lpDesktop)) { + InitOemString(&OemString,lpStartupInfo->lpDesktop); + Unicode.MaximumLength = (USHORT)RtlOemStringToUnicodeSize(&OemString) ; + StartupInfo.lpDesktop = RtlAllocateHeap(RtlProcessHeap(), 0, Unicode.MaximumLength); + if ( !StartupInfo.lpDesktop ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + ReturnStatus = FALSE; + goto tryexit; + } + Unicode.Buffer = StartupInfo.lpDesktop; + Status = RtlOemStringToUnicodeString(&Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnStatus = FALSE; + goto tryexit; + } + } + + if (ARGUMENT_PRESENT(lpStartupInfo->lpTitle)) { + InitOemString(&OemString,lpStartupInfo->lpTitle); + Unicode.MaximumLength = (USHORT)RtlOemStringToUnicodeSize(&OemString) ; + StartupInfo.lpTitle = RtlAllocateHeap(RtlProcessHeap(), 0, Unicode.MaximumLength); + if ( !StartupInfo.lpTitle ) { + BaseSetLastNTError(STATUS_NO_MEMORY); + ReturnStatus = FALSE; + goto tryexit; + } + Unicode.Buffer = StartupInfo.lpTitle; + Status = RtlOemStringToUnicodeString(&Unicode,&OemString,FALSE); + if ( !NT_SUCCESS(Status) ) { + BaseSetLastNTError(Status); + ReturnStatus = FALSE; + goto tryexit; + } + } + ReturnStatus = CreateProcessW( + ApplicationName.Buffer, + DynamicCommandLine.Buffer ? DynamicCommandLine.Buffer : CommandLine->Buffer, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwCreationFlags, + lpEnvironment, + CurrentDirectory.Buffer, + &StartupInfo, + lpProcessInformation + ); +tryexit:; + } + finally { + if (DynamicCommandLine.Buffer) { + RtlFreeUnicodeString(&DynamicCommandLine); + DynamicCommandLine.Buffer = NULL; + } + + if (ApplicationName.Buffer) { + RtlFreeUnicodeString(&ApplicationName); + ApplicationName.Buffer = NULL; + } + + if (CurrentDirectory.Buffer) { + RtlFreeUnicodeString(&CurrentDirectory); + CurrentDirectory.Buffer = NULL; + } + + if (StartupInfo.lpReserved) { + RtlFreeHeap(RtlProcessHeap(), 0,StartupInfo.lpReserved); + StartupInfo.lpReserved = NULL; + } + + if (StartupInfo.lpDesktop) { + RtlFreeHeap(RtlProcessHeap(), 0,StartupInfo.lpDesktop); + StartupInfo.lpDesktop = NULL; + } + + if (StartupInfo.lpTitle) { + RtlFreeHeap(RtlProcessHeap(), 0,StartupInfo.lpTitle); + StartupInfo.lpTitle = NULL; + } + } + return ReturnStatus; + +} +#endif + + + +DWORD +WINAPI +GetEnvironmentVariableOem( + LPSTR lpName, + LPSTR lpBuffer, + DWORD nSize + ) +/*++ + + OEM thunk to GetEnvironmentVariableW + +--*/ +{ + NTSTATUS Status; + UNICODE_STRING Unicode; + OEM_STRING OemString; + ANSI_STRING Name, Buffer; + DWORD ReturnValue; + + Unicode.Buffer = NULL; + Name.Buffer = NULL; + Buffer.Buffer = NULL; + ReturnValue = 0; + try { + + InitOemString(&OemString,lpName); + Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0; + } + + Status = RtlUnicodeStringToAnsiString( &Name, &Unicode, TRUE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + goto try_exit; + } + + Buffer.MaximumLength = (USHORT)nSize; + Buffer.Buffer = (PCHAR) + RtlAllocateHeap( RtlProcessHeap(), 0, Buffer.MaximumLength ); + if (Buffer.Buffer == NULL) { + BaseSetLastNTError( STATUS_NO_MEMORY ); + goto try_exit; + } + + ReturnValue = GetEnvironmentVariableA( Name.Buffer, + Buffer.Buffer, + Buffer.MaximumLength + ); + if (ReturnValue != 0) { + if ( ReturnValue < nSize ) { + Buffer.Length = (USHORT)ReturnValue; + RtlFreeUnicodeString( &Unicode ); + Unicode.Buffer = NULL; + Status = RtlAnsiStringToUnicodeString( &Unicode, &Buffer, TRUE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + ReturnValue = 0; + } + + OemString.Buffer = lpBuffer; + OemString.MaximumLength = (USHORT)nSize; + Status = RtlUnicodeStringToOemString( &OemString, &Unicode, FALSE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + ReturnValue = 0; + } + } + } +try_exit:; + } + finally { + if (Unicode.Buffer != NULL) { + RtlFreeUnicodeString( &Unicode ); + } + + if (Name.Buffer != NULL) { + RtlFreeAnsiString( &Name ); + } + + if (Buffer.Buffer != NULL) { + RtlFreeHeap( RtlProcessHeap(), 0, Buffer.Buffer ); + } + } + + return( ReturnValue ); +} + + + + +BOOL +WINAPI +SetEnvironmentVariableOem( + LPSTR lpName, + LPSTR lpValue + ) +/*++ + + OEM thunk to SetEnvironmentVariableW + +--*/ + +{ + NTSTATUS Status; + UNICODE_STRING Unicode; + OEM_STRING OemString; + ANSI_STRING Name, Value; + DWORD ReturnValue; + + Unicode.Buffer = NULL; + Name.Buffer = NULL; + Value.Buffer = NULL; + ReturnValue = 0; + try { + InitOemString(&OemString, lpName); + Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0; + } + + Status = RtlUnicodeStringToAnsiString( &Name, &Unicode, TRUE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + goto try_exit; + } + RtlFreeUnicodeString( &Unicode ); + Unicode.Buffer = NULL; + + if (ARGUMENT_PRESENT( lpValue )) { + InitOemString(&OemString, lpValue); + Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0; + } + + Status = RtlUnicodeStringToAnsiString( &Value, &Unicode, TRUE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + goto try_exit; + } + + } + + ReturnValue = SetEnvironmentVariableA( Name.Buffer, + Value.Buffer + ); +try_exit:; + } + finally { + if (Unicode.Buffer != NULL) { + RtlFreeUnicodeString( &Unicode ); + } + + if (Name.Buffer != NULL) { + RtlFreeAnsiString( &Name ); + } + + if (Value.Buffer != NULL) { + RtlFreeAnsiString( &Value ); + } + } + + return( ReturnValue ); +} + + + +DWORD +WINAPI +ExpandEnvironmentStringsOem( + LPSTR lpSrc, + LPSTR lpDst, + DWORD cchDst + ) +/*++ + + OEM thunk to ExpandEnvironmentStrings + +--*/ + +{ + + NTSTATUS Status; + UNICODE_STRING Unicode; + OEM_STRING OemString; + ANSI_STRING Name, Value; + DWORD ReturnValue; + + if (!ARGUMENT_PRESENT(lpSrc)){ + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + Unicode.Buffer = NULL; + Name.Buffer = NULL; + Value.Buffer = NULL; + ReturnValue = 0; + try { + InitOemString(&OemString, lpSrc); + Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + return 0; + } + + Status = RtlUnicodeStringToAnsiString( &Name, &Unicode, TRUE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + goto try_exit; + } + RtlFreeUnicodeString( &Unicode ); + Unicode.Buffer = NULL; + + ReturnValue = ExpandEnvironmentStrings( Name.Buffer, + lpDst, + cchDst + ); + if (ReturnValue != 0 && ReturnValue <= cchDst) { + RtlInitString(&Value, lpDst); + Status = RtlAnsiStringToUnicodeString(&Unicode, &Value, TRUE); + if ( !NT_SUCCESS(Status) ) { + if ( Status == STATUS_BUFFER_OVERFLOW ) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + } + else { + BaseSetLastNTError(Status); + } + goto try_exit; + } + Status = RtlUnicodeStringToOemString( &Value, &Unicode, TRUE ); + if (!NT_SUCCESS( Status )) { + BaseSetLastNTError( Status ); + goto try_exit; + } + + } +try_exit:; + } + finally { + if (Unicode.Buffer != NULL) { + RtlFreeUnicodeString( &Unicode ); + } + + if (Name.Buffer != NULL) { + RtlFreeAnsiString( &Name ); + } + + if (Value.Buffer != NULL) { + RtlFreeAnsiString( &Value ); + } + } + + return( ReturnValue ); +} + + +UINT +WINAPI +GetShortPathNameOem( + LPSTR lpSrc, + LPSTR lpDst, + DWORD cchDst + ) +/*++ + + OEM thunk to GetShortPathNameW + +--*/ + +{ + + UNICODE_STRING UString, UStringRet; + OEM_STRING OemString; + NTSTATUS Status; + LPWSTR lpDstW; + DWORD ReturnValue; + + if (lpSrc == NULL) { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + try { + InitOemString(&OemString, lpSrc); + Status = RtlOemStringToUnicodeString(&UString, + &OemString, + TRUE + ); + if (!NT_SUCCESS(Status)){ + BaseSetLastNTError(Status); + return 0; + } + if (ARGUMENT_PRESENT(lpDst) && cchDst > 0) { + lpDstW = RtlAllocateHeap(RtlProcessHeap(), 0, + cchDst * sizeof(WCHAR) + ); + if (lpDstW == NULL) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + } + else { + lpDstW = NULL; + cchDst = 0; + } + ReturnValue = GetShortPathNameW(UString.Buffer, + lpDstW, + cchDst + ); + if (ReturnValue != 0 && ReturnValue <= cchDst) { + if (ARGUMENT_PRESENT(lpDst)) { + OemString.Buffer = lpDst; + OemString.MaximumLength = (USHORT)(cchDst * sizeof(WCHAR)); + UStringRet.Buffer = lpDstW; + UStringRet.Length = (USHORT)(ReturnValue * sizeof(WCHAR)); + Status = RtlUnicodeStringToOemString(&OemString, + &UStringRet, + FALSE + ); + if (!NT_SUCCESS(Status)) { + BaseSetLastNTError(Status); + return 0; + } + } + } + } + finally { + RtlFreeUnicodeString(&UString); + RtlFreeHeap(RtlProcessHeap(), 0, lpDstW); + return ReturnValue; + } +} diff --git a/private/mvdm/oemuni/sources b/private/mvdm/oemuni/sources new file mode 100644 index 000000000..07c3fda7a --- /dev/null +++ b/private/mvdm/oemuni/sources @@ -0,0 +1,45 @@ +!IF 0 + +Copyright (c) 1989-1991 Microsoft Corporation + +Module Name: + + sources. + +Abstract: + + This file specifies the target component being built and the list of + sources files needed to build that component. Also specifies optional + compiler switches and libraries that are unique for the component being + built. + + +History: + Created 14-Jan-1993 Jonle + from template created 12-Apr-1990 by Steve Wood (stevewo) + + +NOTE: Commented description of this file is in \nt\public\oak\bin\sources.tpl + +!ENDIF + +MAJORCOMP=mvdm +MINORCOMP=oemuni + +TARGETNAME=oemuni +TARGETPATH=\nt\public\sdk\lib +TARGETTYPE=LIBRARY +TARGETLIBS= + + +NTPROFILEINPUT=YES + +INCLUDES=.;..\inc;..\..\windows\inc + +SOURCES=file.c \ + process.c + +UMTYPE=console +UMTEST=toemuni +UMAPPL= +UMLIBS=$(_NTDRIVE)\nt\public\sdk\lib\*\oemuni.lib diff --git a/private/mvdm/oemuni/toemuni.c b/private/mvdm/oemuni/toemuni.c new file mode 100644 index 000000000..c94a0c249 --- /dev/null +++ b/private/mvdm/oemuni/toemuni.c @@ -0,0 +1,184 @@ +/* + * Sniff Test for oemuni.lib + * 14-Jan-1993 Jonle , created + */ +#include <nt.h> +#include <ntrtl.h> +#include <nturtl.h> +#include <windows.h> +#include <stdio.h> +#include <conio.h> +#include <string.h> +#include <oemuni.h> + + +void TestDirNode(PCHAR DirName, PCHAR FName); +VOID SetDirectory( PCHAR Name); +VOID SetEnvironment(PCHAR Name,PCHAR Value); +void Pause(void); + + +#define MAXSTR MAX_PATH *2 +char achEnvTMP[MAXSTR+1]; +char achWinDir[MAXSTR+1]; +char achSysDir[MAXSTR+1]; +char achCurDir[MAXSTR+1]; +char ach[MAXSTR+1]; +char achTmp[MAXSTR+1]; + + +DWORD +_CRTAPI1 +main( void) +{ + DWORD dw; + + dw = GetEnvironmentVariableOem("TMP", achEnvTMP, MAXSTR); + if (!dw || dw > MAXSTR-1) + printf("GetEnvironmentVariableOem(TMP) failed dw=%ld\n",dw); + else + printf("TMP=<%s>\n",achEnvTMP); + + dw = GetWindowsDirectoryOem(achWinDir, MAXSTR); + if (!dw || dw > MAXSTR-1) + printf("GetWindowsDirectory failed dw=%ld\n",dw); + else + printf("WinDir=<%s>\n",achWinDir); + + dw = GetSystemDirectoryOem(achSysDir, MAXSTR); + if (!dw || dw > MAXSTR-1) + printf("GetSystemDirectory(achSysDir failed dw=%ld\n",dw); + else + printf("SysDir=<%s>\n",achWinDir); + + dw = GetCurrentDirectory(MAXSTR, achCurDir); + if (!dw || dw > MAXSTR-1) + printf("GetCurrentDirectory(achCurDir dw=%ld\n",dw); + else + printf("CurDir=<%s>\n",achWinDir); + + SetDirectory(achEnvTMP); + SetDirectory(achWinDir); + SetDirectory(achSysDir); + SetDirectory(achCurDir); + Pause(); + + strcpy(ach, achCurDir); + strcat(ach, "\\foo"); + TestDirNode(ach, "foo.foo"); + SetDirectory(achCurDir); + Pause(); + + + dw = GetTempPathOem(MAXSTR, ach); + if (!dw || dw > MAXSTR) + printf("GetTempPathOem - Failed\n"); + else { + printf("GetTempPathOem<%s>\n",ach); + + if (!GetTempFileNameOem(".", "OEM", 0, achTmp)) + printf("GetTempFileNameOem - Failed\n"); + else + printf("GetTempFileNameOem<%s>\n",ach); + + TestDirNode(ach, achTmp); + } + + SetDirectory(achCurDir); + Pause(); + + +} + + + + + +void TestDirNode(PCHAR DirName, PCHAR FName) +{ + HANDLE hFile; + + if (CreateDirectoryOem( DirName, NULL)) + printf("CreateDirectoryOem <%s>\n",DirName); + else + printf("CreateDirectoryOem <%s>- Fail\n",DirName); + + SetDirectory(DirName); + + hFile = CreateFileOem( FName, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + 0); + if (hFile == (HANDLE) 0xFFFFFFFF) { + printf("CreateFileOem<%s>- Fail\n", FName); + } + else { + printf("CreateFileOem<%s>\n", FName); + CloseHandle(hFile); + } + + if (DeleteFileOem(FName)) + printf("DeleteFileOem <%s>\n",FName); + else + printf("DeleteFileOem <%s>- Fail\n",FName); + + + SetDirectory("\\"); + if (RemoveDirectoryOem(DirName)) + printf("RemoveDirectoryOem <%s>\n",DirName); + else + printf("RemoveDirectoryOem <%s>- Fail\n",DirName); +} + + + +VOID +SetDirectory( + PCHAR Name + ) +{ + CHAR achValue[512]; + + if (SetCurrentDirectoryOem( Name)) + printf( "SetCurrentDirectoryOem <%s>\n", Name ? Name : "NULL"); + else + printf( "SetCurrentDirectoryOem- failed\n"); + + if (GetCurrentDirectoryOem( sizeof(achValue)-1, achValue)) + printf( "GetCurrentDirectoryOem <%s>\n", achValue); + else + printf( "GetCurrentDirectoryOem - failed\n"); +} + + + +VOID +SetEnvironment( + PCHAR Name, + PCHAR Value + ) +{ + CHAR achValue[512]; + + if (SetEnvironmentVariableOem( Name, Value )) + printf( "SetEnvironmentVariableOem <%s=%s>\n", Name, Value ? Value : "NULL"); + else + printf( "SetEnvironmentVariableOem - failed\n" ); + + + if (GetEnvironmentVariableOem( Name, achValue, sizeof(achValue)-1)) + printf( "GetEnvironmentVariableOem <%s=%s>\n", Name, achValue ? achValue : "NULL"); + else + printf( "GetEnvironmentVariableOem - failed\n"); +} + + + +void Pause(void) +{ + printf("Press any key ....\n"); + getch(); +} |