Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
getcwd() is part of POSIX, after all.
  • Loading branch information
icculus committed Mar 11, 2012
1 parent b7e0ec7 commit c94d70e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 50 deletions.
6 changes: 0 additions & 6 deletions src/platform_beos.cpp
Expand Up @@ -212,12 +212,6 @@ char *__PHYSFS_platformRealPath(const char *path)
} /* __PHYSFS_platformRealPath */


char *__PHYSFS_platformCurrentDir(void)
{
return(__PHYSFS_platformRealPath(".")); /* let BPath sort it out. */
} /* __PHYSFS_platformCurrentDir */


void *__PHYSFS_platformCreateMutex(void)
{
return(new BLocker("PhysicsFS lock", true));
Expand Down
6 changes: 0 additions & 6 deletions src/platform_macosx.c
Expand Up @@ -314,12 +314,6 @@ char *__PHYSFS_platformRealPath(const char *path)
} /* __PHYSFS_platformRealPath */


char *__PHYSFS_platformCurrentDir(void)
{
return __PHYSFS_platformRealPath("."); /* let CFURL sort it out. */
} /* __PHYSFS_platformCurrentDir */


/* Platform allocator uses default CFAllocator at PHYSFS_init() time. */

static CFAllocatorRef cfallocdef = NULL;
Expand Down
38 changes: 38 additions & 0 deletions src/platform_posix.c
Expand Up @@ -221,6 +221,44 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
} /* __PHYSFS_platformEnumerateFiles */


char *__PHYSFS_platformCurrentDir(void)
{
int allocSize = 64;
char *retval = NULL;
char *ptr;

do
{
allocSize *= 2;
ptr = (char *) allocator.Realloc(retval, allocSize);
if (ptr == NULL)
{
if (retval != NULL)
allocator.Free(retval);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */

retval = ptr;
ptr = getcwd(retval, allocSize);
} while (ptr == NULL && errno == ERANGE);

if (ptr == NULL && errno)
{
/* getcwd() failed , for example current directory not existing... */
if (retval != NULL)
allocator.Free(retval);
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
} /* 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;
} /* __PHYSFS_platformCurrentDir */


int __PHYSFS_platformMkDir(const char *path)
{
int rc;
Expand Down
38 changes: 0 additions & 38 deletions src/platform_unix.c
Expand Up @@ -305,44 +305,6 @@ char *__PHYSFS_platformRealPath(const char *path)
} /* __PHYSFS_platformRealPath */


char *__PHYSFS_platformCurrentDir(void)
{
int allocSize = 64;
char *retval = NULL;
char *ptr;

do
{
allocSize *= 2;
ptr = (char *) allocator.Realloc(retval, allocSize);
if (ptr == NULL)
{
if (retval != NULL)
allocator.Free(retval);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */

retval = ptr;
ptr = getcwd(retval, allocSize);
} while (ptr == NULL && errno == ERANGE);

if (ptr == NULL && errno)
{
/* getcwd() failed , for example current directory not existing... */
if (retval != NULL)
allocator.Free(retval);
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
} /* 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;
} /* __PHYSFS_platformCurrentDir */


int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
{
return 0; /* just use malloc() and friends. */
Expand Down

0 comments on commit c94d70e

Please sign in to comment.