diff --git a/reactos/lib/kernel32/file/dir.c b/reactos/lib/kernel32/file/dir.c index 055110c54f0..4e28b243654 100644 --- a/reactos/lib/kernel32/file/dir.c +++ b/reactos/lib/kernel32/file/dir.c @@ -1,4 +1,4 @@ -/* $Id: dir.c,v 1.50 2004/10/07 21:05:36 gvg Exp $ +/* $Id: dir.c,v 1.51 2004/12/09 17:28:10 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -20,6 +20,7 @@ #define NDEBUG #include "../include/debug.h" +UNICODE_STRING DllDirectory = {0, 0, NULL}; /* FUNCTIONS *****************************************************************/ @@ -878,4 +879,184 @@ SearchPathW ( return retCode / sizeof(WCHAR); } +/* + * @implemented + */ +BOOL +STDCALL +SetDllDirectoryW( + LPCWSTR lpPathName + ) +{ + UNICODE_STRING PathName; + + RtlInitUnicodeString(&PathName, lpPathName); + + RtlEnterCriticalSection(&DllLock); + if(PathName.Length > 0) + { + if(PathName.Length + sizeof(WCHAR) <= DllDirectory.MaximumLength) + { + RtlCopyUnicodeString(&DllDirectory, &PathName); + } + else + { + RtlFreeUnicodeString(&DllDirectory); + if(!(DllDirectory.Buffer = (PWSTR)RtlAllocateHeap(RtlGetProcessHeap(), + 0, + PathName.Length + sizeof(WCHAR)))) + { + RtlLeaveCriticalSection(&DllLock); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + DllDirectory.Length = 0; + DllDirectory.MaximumLength = PathName.Length + sizeof(WCHAR); + + RtlCopyUnicodeString(&DllDirectory, &PathName); + } + } + else + { + RtlFreeUnicodeString(&DllDirectory); + } + RtlLeaveCriticalSection(&DllLock); + + return TRUE; +} + +/* + * @implemented + */ +BOOL +STDCALL +SetDllDirectoryA( + LPCSTR lpPathName + ) +{ + UNICODE_STRING PathNameU; + ANSI_STRING PathNameA; + BOOL Ret; + + if(lpPathName != NULL) + { + RtlInitAnsiString(&PathNameA, lpPathName); + if(bIsFileApiAnsi) + { + RtlAnsiStringToUnicodeString(&PathNameU, &PathNameA, TRUE); + } + else + { + RtlOemStringToUnicodeString(&PathNameU, &PathNameA, TRUE); + } + } + else + { + PathNameU.Buffer = NULL; + } + + Ret = SetDllDirectoryW(PathNameU.Buffer); + + if(lpPathName != NULL) + { + RtlFreeUnicodeString(&PathNameU); + } + + return Ret; +} + +/* + * @implemented + */ +DWORD +STDCALL +GetDllDirectoryW( + DWORD nBufferLength, + LPWSTR lpBuffer + ) +{ + DWORD Ret; + + RtlEnterCriticalSection(&DllLock); + if(nBufferLength > 0) + { + Ret = DllDirectory.Length / sizeof(WCHAR); + if(Ret > nBufferLength - 1) + { + Ret = nBufferLength - 1; + } + + if(Ret > 0) + { + RtlCopyMemory(lpBuffer, DllDirectory.Buffer, Ret * sizeof(WCHAR)); + } + lpBuffer[Ret] = L'\0'; + } + else + { + /* include termination character, even if the string is empty! */ + Ret = (DllDirectory.Length / sizeof(WCHAR)) + 1; + } + RtlLeaveCriticalSection(&DllLock); + + return Ret; +} + +/* + * @implemented + */ +DWORD +STDCALL +GetDllDirectoryA( + DWORD nBufferLength, + LPSTR lpBuffer + ) +{ + UNICODE_STRING PathNameU; + ANSI_STRING PathNameA; + DWORD Ret; + + if(nBufferLength > 0) + { + if(!(PathNameU.Buffer = (PWSTR)RtlAllocateHeap(RtlGetProcessHeap(), + 0, + nBufferLength * sizeof(WCHAR)))) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + PathNameU.Length = 0; + PathNameU.MaximumLength = nBufferLength * sizeof(WCHAR); + } + + Ret = GetDllDirectoryW(nBufferLength, + ((nBufferLength > 0) ? PathNameU.Buffer : NULL)); + + if(nBufferLength > 0) + { + PathNameU.Length = Ret * sizeof(WCHAR); + + PathNameA.Length = 0; + PathNameA.MaximumLength = nBufferLength; + PathNameA.Buffer = lpBuffer; + + if(Ret > 0) + { + if(bIsFileApiAnsi) + { + RtlUnicodeStringToAnsiString(&PathNameA, &PathNameU, FALSE); + } + else + { + RtlUnicodeStringToOemString(&PathNameA, &PathNameU, FALSE); + } + } + lpBuffer[Ret] = '\0'; + + RtlFreeHeap(RtlGetProcessHeap(), 0, PathNameU.Buffer); + } + + return Ret; +} + /* EOF */ diff --git a/reactos/lib/kernel32/include/kernel32.h b/reactos/lib/kernel32/include/kernel32.h index d87ba4a88bd..f6f1f30dc70 100755 --- a/reactos/lib/kernel32/include/kernel32.h +++ b/reactos/lib/kernel32/include/kernel32.h @@ -41,6 +41,8 @@ extern HMODULE hCurrentModule; extern CRITICAL_SECTION DllLock; +extern UNICODE_STRING DllDirectory; + /* FUNCTION PROTOTYPES *******************************************************/ BOOL STDCALL IsConsoleHandle(HANDLE Handle); diff --git a/reactos/lib/kernel32/misc/stubs.c b/reactos/lib/kernel32/misc/stubs.c index a9def634ed3..86b869c0efb 100644 --- a/reactos/lib/kernel32/misc/stubs.c +++ b/reactos/lib/kernel32/misc/stubs.c @@ -1,4 +1,4 @@ -/* $Id: stubs.c,v 1.98 2004/12/07 20:18:49 royce Exp $ +/* $Id: stubs.c,v 1.99 2004/12/09 17:28:10 weiden Exp $ * * KERNEL32.DLL stubs (STUB functions) * Remove from this file, if you implement them. @@ -1154,20 +1154,6 @@ FindNextVolumeMountPointW( return 0; } -/* - * @unimplemented - */ -DWORD -STDCALL -GetDllDirectoryW( - DWORD nBufferLength, - LPWSTR lpBuffer - ) -{ - STUB; - return 0; -} - /* * @unimplemented */ @@ -1306,19 +1292,6 @@ SetComputerNameExW ( return 0; } -/* - * @unimplemented - */ -BOOL -STDCALL -SetDllDirectoryW( - LPCWSTR lpPathName - ) -{ - STUB; - return TRUE; -} - /* * @unimplemented */ @@ -1468,20 +1441,6 @@ FindNextVolumeMountPointA( return 0; } -/* - * @unimplemented - */ -DWORD -STDCALL -GetDllDirectoryA( - DWORD nBufferLength, - LPSTR lpBuffer - ) -{ - STUB; - return 0; -} - /* * @unimplemented */ @@ -1620,19 +1579,6 @@ SetComputerNameExA ( return 0; } -/* - * @unimplemented - */ -BOOL -STDCALL -SetDllDirectoryA( - LPCSTR lpPathName - ) -{ - STUB; - return TRUE; -} - /* * @unimplemented */