[NTDLL]: Reimplement RtlGetCurrentDirectory_U... I couldn't even understand what the old version was doing. This one is at least commented and makes more sense.

svn path=/trunk/; revision=52625
This commit is contained in:
Alex Ionescu 2011-07-11 01:13:34 +00:00
parent 67f44266b0
commit 043ba4e228

View file

@ -159,50 +159,76 @@ RtlIsDosDeviceName_U(PWSTR dos_name)
return 0; return 0;
} }
/* /*
* @implemented * @implemented
*/ */
ULONG NTAPI ULONG
RtlGetCurrentDirectory_U(ULONG MaximumLength, NTAPI
PWSTR Buffer) RtlGetCurrentDirectory_U(IN ULONG MaximumLength,
IN PWSTR Buffer)
{ {
ULONG Length; ULONG Length;
PCURDIR cd; PCURDIR CurDir;
PWSTR CurDirName;
DPRINT("RtlGetCurrentDirectory %lu %p\n", MaximumLength, Buffer);
DPRINT ("RtlGetCurrentDirectory %lu %p\n", MaximumLength, Buffer); /* Lock the PEB to get the current directory */
RtlAcquirePebLock();
CurDir = &NtCurrentPeb()->ProcessParameters->CurrentDirectory;
RtlAcquirePebLock(); /* Get the buffer and character length */
CurDirName = CurDir->DosPath.Buffer;
Length = CurDir->DosPath.Length / sizeof(WCHAR);
ASSERT((CurDirName != NULL) && (Length > 0));
cd = (PCURDIR)&(NtCurrentPeb ()->ProcessParameters->CurrentDirectory.DosPath); /* Check for x:\ vs x:\path\foo (note the trailing slash) */
Length = cd->DosPath.Length / sizeof(WCHAR); Bytes = Length * sizeof(WCHAR);
if (cd->DosPath.Buffer[Length - 1] == L'\\' && if ((Length <= 1) || (CurDirName[Length - 2] == ":"))
cd->DosPath.Buffer[Length - 2] != L':') {
Length--; /* Check if caller does not have enough space */
if (MaximumLength <= Bytes)
{
/* Call has no space for it, fail, add the trailing slash */
RtlReleasePebLock();
return Bytes + sizeof(L'\\');
}
}
else
{
/* Check if caller does not have enough space */
if (MaximumLength <= Bytes)
{
/* Call has no space for it, fail */
RtlReleasePebLock();
return Bytes;
}
}
DPRINT ("cd->DosPath.Buffer %S Length %lu\n", /* Copy the buffer since we seem to have space */
cd->DosPath.Buffer, Length); RtlCopyMemory(Buffer, CurDirName, Bytes);
if (MaximumLength / sizeof(WCHAR) > Length) /* The buffer should end with a path separator */
{ ASSERT(Buffer[Length - 1] == L'\\');
memcpy (Buffer,
cd->DosPath.Buffer,
Length * sizeof(WCHAR));
Buffer[Length] = 0;
}
else
{
Length++;
}
RtlReleasePebLock (); /* Again check for our two cases (drive root vs path) */
if ((Length <= 1) || (Buffer[Length - 2] != ":"))
{
/* Replace the trailing slash with a null */
Buffer[Length - 1] = UNICODE_NULL;
--Length;
}
else
{
/* Append the null char since there's no trailing slash */
Buffer[Length] = UNICODE_NULL;
}
DPRINT ("CurrentDirectory %S\n", Buffer); /* Release PEB lock */
RtlReleasePebLock();
return (Length * sizeof(WCHAR)); DPRINT("CurrentDirectory %S\n", Buffer);
return Length * sizeof(WCHAR);
} }
/* /*
* @implemented * @implemented
*/ */