Modified: trunk/reactos/include/ddk/ldrfuncs.h
Modified: trunk/reactos/lib/kernel32/file/cnotify.c
Modified: trunk/reactos/lib/kernel32/file/curdir.c
Modified: trunk/reactos/lib/kernel32/file/dir.c
Modified: trunk/reactos/lib/kernel32/file/file.c
Modified: trunk/reactos/lib/kernel32/file/hardlink.c
Modified: trunk/reactos/lib/kernel32/file/volume.c
Modified: trunk/reactos/lib/kernel32/include/kernel32.h
Modified: trunk/reactos/lib/kernel32/misc/dllmain.c
Modified: trunk/reactos/lib/kernel32/misc/res.c
Modified: trunk/reactos/lib/kernel32/misc/stubs.c
Modified: trunk/reactos/lib/ntdll/ldr/res.c
Modified: trunk/reactos/lib/ntdll/rtl/path.c
--- trunk/reactos/include/ddk/ldrfuncs.h 2005-03-15 17:38:54 UTC (rev 14100)
+++ trunk/reactos/include/ddk/ldrfuncs.h 2005-03-15 19:40:22 UTC (rev 14101)
@@ -14,12 +14,12 @@
IN ULONG Level,
OUT PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry);
-/*NTSTATUS STDCALL
+NTSTATUS STDCALL
LdrFindResourceDirectory_U( IN PVOID BaseAddress,
- IN PLDR_RESOURCE_INFO ResourceInfo,
+ IN PLDR_RESOURCE_INFO ResourceInfo,
IN ULONG Level,
OUT PIMAGE_RESOURCE_DIRECTORY *ResourceDirectory);
-*/
+
NTSTATUS STDCALL
LdrEnumResources(IN PVOID BaseAddress,
IN PLDR_RESOURCE_INFO ResourceInfo,
--- trunk/reactos/lib/kernel32/file/cnotify.c 2005-03-15 17:38:54 UTC (rev 14100)
+++ trunk/reactos/lib/kernel32/file/cnotify.c 2005-03-15 19:40:22 UTC (rev 14101)
@@ -42,34 +42,14 @@
DWORD dwNotifyFilter
)
{
- UNICODE_STRING PathNameU;
- ANSI_STRING PathName;
- HANDLE hNotify;
+ PWCHAR PathNameW;
- RtlInitAnsiString (&PathName,
- (LPSTR)lpPathName);
+ if (!(PathNameW = FilenameA2W(lpPathName, FALSE)))
+ return INVALID_HANDLE_VALUE;
- /* convert ansi (or oem) string to unicode */
- if (bIsFileApiAnsi)
- {
- RtlAnsiStringToUnicodeString (&PathNameU,
- &PathName,
- TRUE);
- }
- else
- {
- RtlOemStringToUnicodeString (&PathNameU,
- &PathName,
- TRUE);
- }
-
- hNotify = FindFirstChangeNotificationW (PathNameU.Buffer,
+ return FindFirstChangeNotificationW (PathNameW ,
bWatchSubtree,
dwNotifyFilter);
-
- RtlFreeUnicodeString(&PathNameU);
-
- return hNotify;
}
@@ -90,13 +70,6 @@
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hDir;
- /*
- RtlDosPathNameToNtPathName takes a fully qualified file name "C:\Projects\LoadLibrary\Debug\TestDll.dll"
- and returns something like "\??\C:\Projects\LoadLibrary\Debug\TestDll.dll."
- If the file name cannot be interpreted, then the routine returns STATUS_OBJECT_PATH_SYNTAX_BAD and
- ends execution.
- */
-
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpPathName,
&NtPathU,
NULL,
@@ -106,9 +79,11 @@
return INVALID_HANDLE_VALUE;
}
+
+
InitializeObjectAttributes (&ObjectAttributes,
&NtPathU,
- 0,
+ OBJ_CASE_INSENSITIVE,
NULL,
NULL);
@@ -119,6 +94,23 @@
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
FILE_DIRECTORY_FILE);
+ /*
+ FIXME: I think we should use FILE_OPEN_FOR_BACKUP_INTENT. See M$ Q188321
+ -Gunnar
+ */
+
+
+
+ /* FIXME: We free the string alloced by RtlDosPathNameToNtPathName_U, but what
+ * about the special case where the user can pass a \\?\ path? We must not free
+ * the users buffer!. But should we even call RtlDosPathNameToNtPathName_U in that
+ * case??? -Gunnar
+ */
+
+ RtlFreeUnicodeString( &NtPathU);
+
+
+
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
@@ -157,15 +149,16 @@
NTSTATUS Status;
Status = NtNotifyChangeDirectoryFile(hChangeHandle,
- NULL,
- NULL,
- NULL,
- &IoStatus,
- NULL,//Buffer,
- 0,//BufferLength,
- FILE_NOTIFY_CHANGE_SECURITY,//meaningless for subsequent calls, but must contain a valid flag(s)
- 0//meaningless for subsequent calls
- );
+ NULL,
+ NULL,
+ NULL,
+ &IoStatus,
+ NULL,//Buffer,
+ 0,//BufferLength,
+ FILE_NOTIFY_CHANGE_SECURITY,//meaningless/ignored for subsequent calls, but must contain a valid flag
+ 0 //meaningless/ignored for subsequent calls
+ );
+
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
@@ -175,4 +168,62 @@
return TRUE;
}
+
+extern VOID STDCALL
+(ApcRoutine)(PVOID ApcContext,
+ struct _IO_STATUS_BLOCK* IoStatusBlock,
+ ULONG Reserved);
+
+
+/*
+ * @implemented
+ */
+BOOL
+STDCALL
+ReadDirectoryChangesW(
+ HANDLE hDirectory,
+ LPVOID lpBuffer OPTIONAL,
+ DWORD nBufferLength,
+ BOOL bWatchSubtree,
+ DWORD dwNotifyFilter,
+ LPDWORD lpBytesReturned, /* undefined for asych. operations */
+ LPOVERLAPPED lpOverlapped OPTIONAL,
+ LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine /* OPTIONAL???????? */
+ )
+{
+ NTSTATUS Status;
+ IO_STATUS_BLOCK IoStatus;
+
+ if (lpOverlapped )
+ lpOverlapped->Internal = STATUS_PENDING;
+
+ Status = NtNotifyChangeDirectoryFile(
+ hDirectory,
+ lpOverlapped ? lpOverlapped->hEvent : NULL,
+ lpCompletionRoutine ? ApcRoutine : NULL, /* ApcRoutine OPTIONAL???? */
+ lpCompletionRoutine, /* ApcContext */
+ lpOverlapped ? (PIO_STATUS_BLOCK)lpOverlapped : &IoStatus,
+ lpBuffer,
+ nBufferLength,
+ dwNotifyFilter,
+ bWatchSubtree
+ );
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+
+ /* NOTE: lpBytesReturned is undefined for asynch. operations */
+ *lpBytesReturned = IoStatus.Information;
+
+ return TRUE;
+}
+
+
+
+
+
/* EOF */
--- trunk/reactos/lib/kernel32/file/curdir.c 2005-03-15 17:38:54 UTC (rev 14100)
+++ trunk/reactos/lib/kernel32/file/curdir.c 2005-03-15 19:40:22 UTC (rev 14101)
@@ -25,6 +25,9 @@
/* FUNCTIONS *****************************************************************/
+
+
+
/*
* @implemented
*/
@@ -35,71 +38,19 @@
LPSTR lpBuffer
)
{
- ANSI_STRING AnsiString;
- UNICODE_STRING UnicodeString;
- ULONG Length;
+ WCHAR BufferW[MAX_PATH];
+ DWORD ret;
- /* allocate buffer for unicode string */
- UnicodeString.Length = 0;
- UnicodeString.MaximumLength = nBufferLength * sizeof(WCHAR);
- if (nBufferLength > 0)
- {
- UnicodeString.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
- 0,
- UnicodeString.MaximumLength);
+ ret = GetCurrentDirectoryW(MAX_PATH, BufferW);
- /* initialize ansi string */
- AnsiString.Length = 0;
- AnsiString.MaximumLength = nBufferLength;
- AnsiString.Buffer = lpBuffer;
- }
- else
- {
- UnicodeString.Buffer = NULL;
- }
-
- /* get current directory */
- UnicodeString.Length = RtlGetCurrentDirectory_U (UnicodeString.MaximumLength,
- UnicodeString.Buffer);
- DPRINT("UnicodeString.Buffer %wZ\n", &UnicodeString);
-
- /* convert unicode string to ansi (or oem) */
- if (bIsFileApiAnsi)
- {
- Length = RtlUnicodeStringToAnsiSize (&UnicodeString);
- if (Length > nBufferLength)
- {
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- UnicodeString.Buffer);
- return Length-1;
- }
- RtlUnicodeStringToAnsiString (&AnsiString,
- &UnicodeString,
- FALSE);
- }
- else
- {
- Length = RtlUnicodeStringToOemSize (&UnicodeString);
- if (Length > nBufferLength)
- {
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- UnicodeString.Buffer);
- return Length-1;
- }
- RtlUnicodeStringToOemString (&AnsiString,
- &UnicodeString,
- FALSE);
- }
- DPRINT("AnsiString.Buffer %s\n", AnsiString.Buffer);
-
- /* free unicode string */
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- UnicodeString.Buffer);
-
- return AnsiString.Length;
+ if (!ret) return 0;
+ if (ret > MAX_PATH)
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return 0;
+ }
+
+ return FilenameW2A_FitOrFail(lpBuffer, nBufferLength, BufferW, ret+1);
}
@@ -122,6 +73,7 @@
}
+
/*
* @implemented
*/
@@ -131,27 +83,16 @@
LPCSTR lpPathName
)
{
- ANSI_STRING AnsiString;
- UNICODE_STRING UnicodeString;
+ PUNICODE_STRING PathNameU;
NTSTATUS Status;
- RtlInitAnsiString (&AnsiString,
- (LPSTR)lpPathName);
+ DPRINT("setcurrdir: %s\n",lpPathName);
- /* convert ansi (or oem) to unicode */
- if (bIsFileApiAnsi)
- RtlAnsiStringToUnicodeString (&UnicodeString,
- &AnsiString,
- TRUE);
- else
- RtlOemStringToUnicodeString (&UnicodeString,
- &AnsiString,
- TRUE);
+ if (!(PathNameU = FilenameA2U(lpPathName, FALSE)))
+ return FALSE;
- Status = RtlSetCurrentDirectory_U (&UnicodeString);
+ Status = RtlSetCurrentDirectory_U(PathNameU);
- RtlFreeUnicodeString (&UnicodeString);
-
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
@@ -190,6 +131,8 @@
/*
* @implemented
+ *
+ * NOTE: Windows returns a dos/short (8.3) path
*/
DWORD
STDCALL
@@ -198,138 +141,82 @@
LPSTR lpBuffer
)
{
- UNICODE_STRING UnicodeString;
- ANSI_STRING AnsiString;
- DWORD Length;
+ WCHAR BufferW[MAX_PATH];
+ DWORD ret;
- AnsiString.Length = 0;
- AnsiString.MaximumLength = nBufferLength;
- AnsiString.Buffer = lpBuffer;
+ ret = GetTempPathW(MAX_PATH, BufferW);
- /* initialize allocate unicode string */
- UnicodeString.Length = 0;
- if(nBufferLength > 0)
- {
- UnicodeString.MaximumLength = (nBufferLength + 1) * sizeof(WCHAR);
- UnicodeString.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
- 0,
- UnicodeString.MaximumLength);
- if (UnicodeString.Buffer == NULL)
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
- }
- else
- {
- UnicodeString.MaximumLength = 0;
- UnicodeString.Buffer = NULL;
- }
+ if (!ret)
+ return 0;
- Length = GetTempPathW (nBufferLength,
- UnicodeString.Buffer);
+ if (ret > MAX_PATH)
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return 0;
+ }
- if (nBufferLength >= Length)
- {
- /* only touch the buffer if the supplied buffer length is at least
- the length that GetTempPathW returned! */
- UnicodeString.Length = Length * sizeof(WCHAR);
-
- /* convert unicode string to ansi (or oem) */
- if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString (&AnsiString,
- &UnicodeString,
- FALSE);
- else
- RtlUnicodeStringToOemString (&AnsiString,
- &UnicodeString,
- FALSE);
- }
-
- /* free unicode string buffer */
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- UnicodeString.Buffer);
-
- return Length;
+ return FilenameW2A_FitOrFail(lpBuffer, nBufferLength, BufferW, ret+1);
}
/*
* @implemented
+ *
+ * ripped from wine
*/
DWORD
STDCALL
GetTempPathW (
- DWORD nBufferLength,
- LPWSTR lpBuffer
+ DWORD count,
+ LPWSTR path
)
{
- UNICODE_STRING Name;
- PUNICODE_STRING Value;
- PTEB Teb;
- DWORD Length;
- NTSTATUS Status;
+ WCHAR tmp_path[MAX_PATH];
+ WCHAR tmp_full_path[MAX_PATH];
+ UINT ret;
- Teb = NtCurrentTeb();
- Teb->StaticUnicodeString.Length = 0;
- Teb->StaticUnicodeString.MaximumLength = MAX_PATH * sizeof(WCHAR);
- Teb->StaticUnicodeString.Buffer = Teb->StaticUnicodeBuffer;
- Value = &Teb->StaticUnicodeString;
+ DPRINT("GetTempPathW(%lu,%p)\n", nBufferLength, lpBuffer);
- RtlRosInitUnicodeStringFromLiteral (&Name,
- L"TMP");
+ if (!(ret = GetEnvironmentVariableW( L"TMP", tmp_path, MAX_PATH )))
+ if (!(ret = GetEnvironmentVariableW( L"TEMP", tmp_path, MAX_PATH )))
+ if (!(ret = GetCurrentDirectoryW( MAX_PATH, tmp_path )))
+ return 0;
- Status = RtlQueryEnvironmentVariable_U (NULL,
- &Name,
- Value);
- if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
- {
- RtlRosInitUnicodeStringFromLiteral (&Name,
- L"TEMP");
+ if (ret > MAX_PATH)
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return 0;
+ }
- Status = RtlQueryEnvironmentVariable_U (NULL,
- &Name,
- Value);
- if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
- {
- Value->Length = RtlGetCurrentDirectory_U(Value->MaximumLength,
- Value->Buffer);
- }
- }
+ ret = GetFullPathNameW(tmp_path, MAX_PATH, tmp_full_path, NULL);
+ if (!ret) return 0;
- if (!NT_SUCCESS(Status))
- {
- SetLastError(RtlNtStatusToDosError(Status));
- return 0;
- }
+ if (ret > MAX_PATH - 2)
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return 0;
+ }
- Length = Value->Length / sizeof(WCHAR) + 1;
- if (nBufferLength < Value->Length / sizeof(WCHAR) + 2)
- Length++;
+ if (tmp_full_path[ret-1] != '\\')
+ {
+ tmp_full_path[ret++] = '\\';
+ tmp_full_path[ret] = '\0';
+ }
- if (nBufferLength >= Value->Length /sizeof(WCHAR) + 1)
- {
- if (nBufferLength < Value->Length / sizeof(WCHAR) + 2)
- {
- memcpy (lpBuffer,
- Value->Buffer,
- nBufferLength * sizeof(WCHAR));
- }
- else
- {
- memcpy (lpBuffer,
- Value->Buffer,
- Value->Length);
- lpBuffer[Value->Length / sizeof(WCHAR)] = L'\\';
- lpBuffer[Value->Length / sizeof(WCHAR) + 1] = 0;
- }
- } else if (nBufferLength > 0)
- {
- lpBuffer[0] = L'\0';
- }
+ ret++; /* add space for terminating 0 */
- return Length;
+ if (count)
+ {
+ lstrcpynW(path, tmp_full_path, count);
+ if (count >= ret)
+ ret--; /* return length without 0 */
+ else if (count < 4)
+ path[0] = 0; /* avoid returning ambiguous "X:" */
+ }
+
+ DPRINT("GetTempPathW returning %u, %s\n", ret, path);
+ return ret;
+
}
@@ -343,37 +230,7 @@
UINT uSize
)
{
- ANSI_STRING String;
- ULONG Length;
- NTSTATUS Status;
-
- Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); //len of ansi str incl. nullchar
-
- if (lpBuffer == NULL)
- return Length;
-
- if (uSize >= Length){
- String.Length = 0;
- String.MaximumLength = uSize;
- String.Buffer = lpBuffer;
-
- /* convert unicode string to ansi (or oem) */
- if (bIsFileApiAnsi)
- Status = RtlUnicodeStringToAnsiString (&String,
- &SystemDirectory,
- FALSE);
- else
- Status = RtlUnicodeStringToOemString (&String,
- &SystemDirectory,
- FALSE);
- if (!NT_SUCCESS(Status) )
- return 0;
-
- return Length-1; //good: ret chars excl. nullchar
-
- }
-
- return Length; //bad: ret space needed incl. nullchar
+ return FilenameU2A_FitOrFail(lpBuffer, uSize, &SystemDirectory);
}
@@ -416,38 +273,7 @@
UINT uSize
)
{
- ANSI_STRING String;
- ULONG Length;
- NTSTATUS Status;
-
- Length = RtlUnicodeStringToAnsiSize (&WindowsDirectory); //len of ansi str incl. nullchar
-
- if (lpBuffer == NULL)
- return Length;
-
- if (uSize >= Length){
-
- String.Length = 0;
- String.MaximumLength = uSize;
- String.Buffer = lpBuffer;
-
- /* convert unicode string to ansi (or oem) */
- if (bIsFileApiAnsi)
- Status = RtlUnicodeStringToAnsiString (&String,
- &WindowsDirectory,
- FALSE);
- else
- Status = RtlUnicodeStringToOemString (&String,
- &WindowsDirectory,
- FALSE);
-
- if (!NT_SUCCESS(Status))
- return 0;
-
- return Length-1; //good: ret chars excl. nullchar
- }
-
- return Length; //bad: ret space needed incl. nullchar
+ return FilenameU2A_FitOrFail(lpBuffer, uSize, &WindowsDirectory);
}
--- trunk/reactos/lib/kernel32/file/dir.c 2005-03-15 17:38:54 UTC (rev 14100)
+++ trunk/reactos/lib/kernel32/file/dir.c 2005-03-15 19:40:22 UTC (rev 14101)
@@ -50,65 +50,26 @@
LPCSTR lpNewDirectory,
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
- UNICODE_STRING TmplDirU;
- UNICODE_STRING NewDirU;
- ANSI_STRING TmplDir;
- ANSI_STRING NewDir;
- BOOL Result;
+ PWCHAR TemplateDirectoryW;
+ PWCHAR NewDirectoryW;
+ BOOL ret;
- RtlInitUnicodeString (&TmplDirU,
- NULL);
+ if (!(TemplateDirectoryW = FilenameA2W(lpTemplateDirectory, FALSE)))
+ return FALSE;
+
+ if (!(NewDirectoryW = FilenameA2W(lpNewDirectory, TRUE)))
+ return FALSE;
+
+ ret = CreateDirectoryExW (TemplateDirectoryW,
+ NewDirectoryW,
+ lpSecurityAttributes);
- RtlInitUnicodeString (&NewDirU,
- NULL);
+ if (lpNewDirectory != NULL)
+ RtlFreeHeap (RtlGetProcessHeap (),
+ 0,
+ NewDirectoryW);
- if (lpTemplateDirectory != NULL)
- {
- RtlInitAnsiString (&TmplDir,
- (LPSTR)lpTemplateDirectory);
-
- /* convert ansi (or oem) string to unicode */
- 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;
+ return ret;
}
@@ -215,30 +176,14 @@
LPCSTR lpPathName
)
{
- UNICODE_STRING PathNameU;
- ANSI_STRING PathName;
- BOOL Result;
+ PWCHAR PathNameW;
+
+ DPRINT("RemoveDirectoryA(%s)\n",lpPathName);
- RtlInitAnsiString (&PathName,
- (LPSTR)lpPathName);
+ if (!(PathNameW = FilenameA2W(lpPathName, FALSE)))
+ return FALSE;
- /* convert ansi (or oem) string to unicode */
- if (bIsFileApiAnsi)
- RtlAnsiStringToUnicodeString (&PathNameU,
- &PathName,
- TRUE);
- else
- RtlOemStringToUnicodeString (&PathNameU,
- &PathName,
- TRUE);
-
- Result = RemoveDirectoryW (PathNameU.Buffer);
-
- RtlFreeHeap (RtlGetProcessHeap (),
- 0,
- PathNameU.Buffer);
-
- return Result;
+ return RemoveDirectoryW (PathNameW);
}
@@ -337,70 +282,49 @@
LPSTR *lpFilePart
)
{
- UNICODE_STRING nameW;
- WCHAR bufferW[MAX_PATH];
- DWORD ret;
- LPWSTR FilePart = NULL;
+ WCHAR BufferW[MAX_PATH];
+ PWCHAR FileNameW;
+ DWORD ret;
+ LPWSTR FilePartW = NULL;
- DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
- "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
+ DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
+ "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
- if (!lpFileName)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
+ if (!lpFileName)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
- if (!RtlCreateUnicodeStringFromAsciiz(&nameW, (LPSTR)lpFileName))
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
+ if (!(FileNameW = FilenameA2W(lpFileName, FALSE)))
+ return 0;
- if (lpFilePart)
- {
- *lpFilePart = NULL;
- }
+ ret = GetFullPathNameW(FileNameW, MAX_PATH, BufferW, &FilePartW);
+
+ if (!ret)
+ return 0;
+
+ if (ret > MAX_PATH)
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return 0;
+ }
+
+ ret = FilenameW2A_FitOrFail(lpBuffer, nBufferLength, BufferW, ret+1);
+
+ if (ret < nBufferLength && lpFilePart)
+ {
+ /* if the path closed with '\', FilePart is NULL */
+ if (!FilePartW)
+ *lpFilePart=NULL;
+ else
+ *lpFilePart = (FilePartW - BufferW) + lpBuffer;
+ }
+
+ DPRINT("GetFullPathNameA ret: lpBuffer %s lpFilePart %s\n",
+ lpBuffer, (lpFilePart == NULL) ? "NULL" : *lpFilePart);
- ret = GetFullPathNameW(nameW.Buffer, MAX_PATH, bufferW, &FilePart);
-
- if (MAX_PATH < ret)
- {
- SetLastError(ERROR_FILENAME_EXCED_RANGE);
- ret = 0;
- }
- else if (0 < ret)
- {
- if (ret < nBufferLength)
- {
- ANSI_STRING AnsiBuffer;
- UNICODE_STRING UnicodeBuffer;
-
- UnicodeBuffer.Length = wcslen(bufferW) * sizeof(WCHAR);
- UnicodeBuffer.MaximumLength = MAX_PATH * sizeof(WCHAR);
- UnicodeBuffer.Buffer = bufferW;
- AnsiBuffer.MaximumLength = nBufferLength;
- AnsiBuffer.Length = 0;
- AnsiBuffer.Buffer = lpBuffer;
- RtlUnicodeStringToAnsiString(&AnsiBuffer, &UnicodeBuffer, FALSE);
-
- if (lpFilePart && FilePart != NULL)
- {
- *lpFilePart = (FilePart - bufferW) + lpBuffer;
- }
- }
- else
- {
- ret++;
- }
- }
-
- RtlFreeUnicodeString(&nameW);
-
- DPRINT("lpBuffer %s lpFilePart %s Length %ld\n",
- lpBuffer, (lpFilePart == NULL) ? "NULL" : *lpFilePart, nameW.Length);
-
- return ret;
+ return ret;
}
@@ -426,17 +350,10 @@
lpBuffer,
lpFilePart);
- DPRINT("lpBuffer %S lpFilePart %S Length %ld\n",
+ DPRINT("GetFullPathNameW ret: lpBuffer %S lpFilePart %S Length %ld\n",
lpBuffer, (lpFilePart == NULL) ? L"NULL" : *lpFilePart, Length / sizeof(WCHAR));
- Length = Length / sizeof(WCHAR);
- if (nBufferLength < Length + 1)
- {
- DPRINT("Adjusting Length for terminator\n");
- Length++;
- }
-
- return Length;
+ return Length/sizeof(WCHAR);
}
@@ -452,9 +369,9 @@
DWORD shortlen
)
{
- UNICODE_STRING longpathW;
- WCHAR shortpathW[MAX_PATH];
- DWORD ret, retW;
+ PWCHAR LongPathW;
+ WCHAR ShortPathW[MAX_PATH];
+ DWORD ret;
if (!longpath)
{
@@ -462,33 +379,21 @@
return 0;
}
- if (!RtlCreateUnicodeStringFromAsciiz(&longpathW, longpath))
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
+ if (!(LongPathW = FilenameA2W(longpath, FALSE)))
+ return 0;
- retW = GetShortPathNameW(longpathW.Buffer, shortpathW, MAX_PATH);
+ ret = GetShortPathNameW(LongPathW, ShortPathW, MAX_PATH);
- if (!retW)
- ret = 0;
- else if (retW > PATH_MAX)
+ if (!ret)
+ return 0;
+
+ if (ret > MAX_PATH)
{
SetLastError(ERROR_FILENAME_EXCED_RANGE);
- ret = 0;
+ return 0;
}
- else
- {
- ret = WideCharToMultiByte(CP_ACP, 0, shortpathW, -1, NULL, 0, NULL, NULL);
- if (ret <= shortlen)
- {
- WideCharToMultiByte(CP_ACP, 0, shortpathW, -1, shortpath, shortlen, NULL, NULL);
- ret--; /* length without 0 */
- }
- }
-
- RtlFreeUnicodeString(&longpathW);
- return ret;
+
+ return FilenameW2A_FitOrFail(shortpath, shortlen, ShortPathW, ret+1);
}
@@ -513,6 +418,8 @@
UNICODE_STRING ustr;
WCHAR ustr_buf[8+1+3+1];
+ DPRINT("GetShortPathNameW: %S\n",longpath);
+
if (!longpath)
{
SetLastError(ERROR_INVALID_PARAMETER);
@@ -931,38 +838,18 @@
BOOL
STDCALL
SetDllDirectoryA(
- LPCSTR lpPathName
+ LPCSTR lpPathName /* can be NULL */
)
{
- UNICODE_STRING PathNameU;
- ANSI_STRING PathNameA;
- BOOL Ret;
+ PWCHAR PathNameW=NULL;
- if(lpPathName != NULL)
+ if(lpPathName)
{
- RtlInitAnsiString(&PathNameA, lpPathName);
- if(bIsFileApiAnsi)
- {
- RtlAnsiStringToUnicodeString(&PathNameU, &PathNameA, TRUE);
- }
- else
- {
- RtlOemStringToUnicodeString(&PathNameU, &PathNameA, TRUE);
- }
+ if (!(PathNameW = FilenameA2W(lpPathName, FALSE)))
+ return FALSE;
}
- else
- {
- PathNameU.Buffer = NULL;
- }
- Ret = SetDllDirectoryW(PathNameU.Buffer);
-
- if(lpPathName != NULL)
- {
- RtlFreeUnicodeString(&PathNameU);
- }
-
- return Ret;
+ return SetDllDirectoryW(PathNameW);
}
/*
@@ -1012,51 +899,21 @@
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);
[truncated at 1000 lines; 1806 more skipped]