Change how Unix version of __PHYSFS_platformCurrentDir() allocates memory.
This commit is contained in:
parent
7a8e3de103
commit
b7e0ec7391
|
@ -307,18 +307,13 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
|
|
||||||
char *__PHYSFS_platformCurrentDir(void)
|
char *__PHYSFS_platformCurrentDir(void)
|
||||||
{
|
{
|
||||||
/*
|
int allocSize = 64;
|
||||||
* This can't just do platformRealPath("."), since that would eventually
|
|
||||||
* just end up calling back into here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int allocSize = 0;
|
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
allocSize += 100;
|
allocSize *= 2;
|
||||||
ptr = (char *) allocator.Realloc(retval, allocSize);
|
ptr = (char *) allocator.Realloc(retval, allocSize);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
|
@ -333,15 +328,17 @@ char *__PHYSFS_platformCurrentDir(void)
|
||||||
|
|
||||||
if (ptr == NULL && errno)
|
if (ptr == NULL && errno)
|
||||||
{
|
{
|
||||||
/*
|
/* getcwd() failed , for example current directory not existing... */
|
||||||
* getcwd() failed for some reason, for example current
|
|
||||||
* directory not existing.
|
|
||||||
*/
|
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
allocator.Free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
/* try to shrink buffer... */
|
||||||
|
ptr = (char *) allocator.Realloc(retval, strlen(retval) + 1);
|
||||||
|
if (ptr != NULL)
|
||||||
|
retval = ptr; /* oh well if it failed. */
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* __PHYSFS_platformCurrentDir */
|
} /* __PHYSFS_platformCurrentDir */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue