mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 16:43:04 +00:00
[CRT]
Rewritten _tfullpath(). This: - Fixes memory leak - Fixes null pointer use - Adds missing features - Sets errno svn path=/trunk/; revision=53782
This commit is contained in:
parent
e91d38160f
commit
0194a753c7
1 changed files with 53 additions and 13 deletions
|
@ -1,11 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS CRT library
|
||||||
* FILE: lib/msvcrt/stdlib/fullpath.c
|
* FILE: lib/sdk/crt/stdlib/fullpath.c
|
||||||
* PURPOSE: Gets the fullpathname
|
* PURPOSE: Gets the fullpathname
|
||||||
* PROGRAMER: Ariadne
|
* PROGRAMER: Pierre Schweitzer (pierre.schweitzer@reactos.org)
|
||||||
* UPDATE HISTORY:
|
|
||||||
* 28/12/98: Created
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
|
@ -16,18 +14,60 @@
|
||||||
*/
|
*/
|
||||||
_TCHAR* _tfullpath(_TCHAR* absPath, const _TCHAR* relPath, size_t maxLength)
|
_TCHAR* _tfullpath(_TCHAR* absPath, const _TCHAR* relPath, size_t maxLength)
|
||||||
{
|
{
|
||||||
|
_TCHAR* lpBuffer;
|
||||||
_TCHAR* lpFilePart;
|
_TCHAR* lpFilePart;
|
||||||
DWORD copied;
|
DWORD retval;
|
||||||
|
|
||||||
if (!absPath)
|
/* First check if entry relative path was given */
|
||||||
|
if (!relPath || relPath[0] == 0)
|
||||||
{
|
{
|
||||||
maxLength = MAX_PATH;
|
/* If not, just try to return current dir */
|
||||||
absPath = malloc(maxLength);
|
return _tgetcwd(absPath, maxLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
copied = GetFullPathName(relPath,(DWORD)maxLength,absPath,&lpFilePart);
|
/* If no output buffer was given */
|
||||||
if (copied == 0 || copied > maxLength)
|
if (!absPath)
|
||||||
return NULL;
|
{
|
||||||
|
/* Allocate one with fixed length */
|
||||||
|
maxLength = MAX_PATH;
|
||||||
|
lpBuffer = malloc(maxLength);
|
||||||
|
if (!lpBuffer)
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lpBuffer = absPath;
|
||||||
|
}
|
||||||
|
|
||||||
return absPath;
|
/* Really get full path */
|
||||||
|
retval = GetFullPathName(relPath, (DWORD)maxLength, lpBuffer, &lpFilePart);
|
||||||
|
/* Check for failures */
|
||||||
|
if (retval > maxLength)
|
||||||
|
{
|
||||||
|
/* Path too long, free (if needed) and return */
|
||||||
|
if (!absPath)
|
||||||
|
{
|
||||||
|
free(lpBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = ERANGE;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else if (!retval)
|
||||||
|
{
|
||||||
|
/* Other error, free (if needed), translate error, and return */
|
||||||
|
if (!absPath)
|
||||||
|
{
|
||||||
|
free(lpBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
_dosmaperr(GetLastError());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return buffer. Up to the caller to free if needed */
|
||||||
|
return lpBuffer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue