From c94d70ec0a7d517aca9a721b72af7c0a7be8a541 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 11 Mar 2012 03:43:07 -0400 Subject: [PATCH] Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources. getcwd() is part of POSIX, after all. --- src/platform_beos.cpp | 6 ------ src/platform_macosx.c | 6 ------ src/platform_posix.c | 38 ++++++++++++++++++++++++++++++++++++++ src/platform_unix.c | 38 -------------------------------------- 4 files changed, 38 insertions(+), 50 deletions(-) diff --git a/src/platform_beos.cpp b/src/platform_beos.cpp index aae29842..0f454f63 100644 --- a/src/platform_beos.cpp +++ b/src/platform_beos.cpp @@ -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)); diff --git a/src/platform_macosx.c b/src/platform_macosx.c index 17ffb9a6..06cb8abf 100644 --- a/src/platform_macosx.c +++ b/src/platform_macosx.c @@ -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; diff --git a/src/platform_posix.c b/src/platform_posix.c index c14a1699..d2b079ec 100644 --- a/src/platform_posix.c +++ b/src/platform_posix.c @@ -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; diff --git a/src/platform_unix.c b/src/platform_unix.c index 549548dd..bd212920 100644 --- a/src/platform_unix.c +++ b/src/platform_unix.c @@ -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. */