Fix GetFullPathNameA/W() return value

svn path=/trunk/; revision=11220
This commit is contained in:
Gé van Geldorp 2004-10-07 20:39:04 +00:00
parent ed6cee0a13
commit 8438655244

View file

@ -1,4 +1,4 @@
/* $Id: dir.c,v 1.48 2004/08/18 02:13:27 navaraf Exp $ /* $Id: dir.c,v 1.49 2004/10/07 20:39:04 gvg 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
@ -336,70 +336,71 @@ GetFullPathNameA (
LPSTR *lpFilePart LPSTR *lpFilePart
) )
{ {
UNICODE_STRING nameW; UNICODE_STRING nameW;
WCHAR bufferW[MAX_PATH]; WCHAR bufferW[MAX_PATH];
DWORD ret, retW; DWORD ret;
LPWSTR FilePart = NULL; LPWSTR FilePart = NULL;
DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, " if (0 == nBufferLength) __asm__("int $3\n");
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart); DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
if (!lpFileName) if (!lpFileName)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
if (!RtlCreateUnicodeStringFromAsciiz(&nameW, (LPSTR)lpFileName))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
if (lpFilePart)
{
*lpFilePart = NULL;
}
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)
{ {
SetLastError(ERROR_INVALID_PARAMETER); ANSI_STRING AnsiBuffer;
return 0; UNICODE_STRING UnicodeBuffer;
}
if (!RtlCreateUnicodeStringFromAsciiz(&nameW, (LPSTR)lpFileName)) UnicodeBuffer.Length = wcslen(bufferW) * sizeof(WCHAR);
{ UnicodeBuffer.MaximumLength = MAX_PATH * sizeof(WCHAR);
SetLastError(ERROR_NOT_ENOUGH_MEMORY); UnicodeBuffer.Buffer = bufferW;
return 0; AnsiBuffer.MaximumLength = nBufferLength;
} AnsiBuffer.Length = 0;
AnsiBuffer.Buffer = lpBuffer;
RtlUnicodeStringToAnsiString(&AnsiBuffer, &UnicodeBuffer, FALSE);
if (lpFilePart) if (lpFilePart && FilePart != NULL)
{ {
*lpFilePart = NULL; *lpFilePart = (FilePart - bufferW) + lpBuffer;
} }
retW = GetFullPathNameW(nameW.Buffer, MAX_PATH, bufferW, &FilePart);
if (!retW)
{
ret = 0;
}
else if (retW > MAX_PATH)
{
SetLastError(ERROR_FILENAME_EXCED_RANGE);
ret = 0;
} }
else else
{ {
ANSI_STRING AnsiBuffer; ret++;
UNICODE_STRING UnicodeBuffer;
UnicodeBuffer.Length = wcslen(bufferW) * sizeof(WCHAR);
ret = nameW.Length;
if (nameW.Length <= nBufferLength)
{
UnicodeBuffer.Buffer = bufferW;
AnsiBuffer.MaximumLength = nBufferLength;
AnsiBuffer.Length = 0;
AnsiBuffer.Buffer = lpBuffer;
RtlUnicodeStringToAnsiString(&AnsiBuffer, &UnicodeBuffer, FALSE);
if (lpFilePart && FilePart != NULL)
{
*lpFilePart = (FilePart - bufferW) + lpBuffer;
}
}
} }
}
RtlFreeUnicodeString(&nameW); RtlFreeUnicodeString(&nameW);
DPRINT("lpBuffer %s lpFilePart %s Length %ld\n", DPRINT("lpBuffer %s lpFilePart %s Length %ld\n",
lpBuffer, (lpFilePart == NULL) ? "NULL" : *lpFilePart, nameW.Length); lpBuffer, (lpFilePart == NULL) ? "NULL" : *lpFilePart, nameW.Length);
return ret; return ret;
} }
@ -415,20 +416,27 @@ GetFullPathNameW (
LPWSTR *lpFilePart LPWSTR *lpFilePart
) )
{ {
ULONG Length; ULONG Length;
DPRINT("GetFullPathNameW(lpFileName %S, nBufferLength %d, lpBuffer %p, " DPRINT("GetFullPathNameW(lpFileName %S, nBufferLength %d, lpBuffer %p, "
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart); "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
Length = RtlGetFullPathName_U ((LPWSTR)lpFileName, Length = RtlGetFullPathName_U ((LPWSTR)lpFileName,
nBufferLength * sizeof(WCHAR), nBufferLength * sizeof(WCHAR),
lpBuffer, lpBuffer,
lpFilePart); lpFilePart);
DPRINT("lpBuffer %S lpFilePart %S Length %ld\n", DPRINT("lpBuffer %S lpFilePart %S Length %ld\n",
lpBuffer, (lpFilePart == NULL) ? L"NULL" : *lpFilePart, Length / sizeof(WCHAR)); lpBuffer, (lpFilePart == NULL) ? L"NULL" : *lpFilePart, Length / sizeof(WCHAR));
return (Length / sizeof(WCHAR)); Length = Length / sizeof(WCHAR);
if (nBufferLength < Length + 1)
{
DPRINT("Adjusting Length for terminator\n");
Length++;
}
return Length;
} }