From a0af6bbb71d55c94438dd1e0f04d24a442e5213e Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 22 Mar 2012 00:27:46 -0400 Subject: [PATCH] Removed fallback for systems that have no userdir. This would try to build something under the basedir for Windows 95, OS/2, etc, but those targets are gone now. Modern systems provide this. If a given system can't in the future, they can pull this code out of revision control and use it in their implementation of __PHYSFS_platformCalcUserDir(). This change let me remove __PHYSFS_platformGetUserName(), too. --- src/physfs.c | 24 +----------------------- src/physfs_internal.h | 7 ------- src/platform_posix.c | 27 --------------------------- src/platform_windows.c | 20 -------------------- 4 files changed, 1 insertion(+), 77 deletions(-) diff --git a/src/physfs.c b/src/physfs.c index 9e3cff5..d87574d 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -1102,28 +1102,6 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList) } /* freeDirHandle */ -static char *calculateUserDir(void) -{ - char *retval = __PHYSFS_platformCalcUserDir(); - if (retval == NULL) - { - const char dirsep = __PHYSFS_platformDirSeparator; - const char *uname = __PHYSFS_platformGetUserName(); - const char *str = (uname != NULL) ? uname : "default"; - const size_t len = strlen(baseDir) + strlen(str) + 7; - - retval = (char *) allocator.Malloc(len); - if (retval == NULL) - __PHYSFS_setError(PHYSFS_ERR_OUT_OF_MEMORY); - else - sprintf(retval, "%susers%c%s", baseDir, dirsep, str); - - allocator.Free((void *) uname); - } /* else */ - - return retval; -} /* calculateUserDir */ - /* * !!! FIXME: remove this and require userdir and basedir to have dirsep * !!! FIXME: appended in the platform layer @@ -1227,7 +1205,7 @@ int PHYSFS_init(const char *argv0) BAIL_IF_MACRO(!appendDirSep(&baseDir), ERRPASS, 0); - userDir = calculateUserDir(); + userDir = __PHYSFS_platformCalcUserDir(); if ((!userDir) || (!appendDirSep(&userDir))) { allocator.Free(baseDir); diff --git a/src/physfs_internal.h b/src/physfs_internal.h index c6880d8..73dd13e 100644 --- a/src/physfs_internal.h +++ b/src/physfs_internal.h @@ -626,13 +626,6 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data); */ char *__PHYSFS_platformCalcBaseDir(const char *argv0); -/* - * Get the platform-specific user name. - * Caller will allocator.Free() the retval if it's not NULL. If it's NULL, - * the username will default to "default". - */ -char *__PHYSFS_platformGetUserName(void); - /* * Get the platform-specific user dir. * Caller will allocator.Free() the retval if it's not NULL. If it's NULL, diff --git a/src/platform_posix.c b/src/platform_posix.c index c493aa3..7b82f62 100644 --- a/src/platform_posix.c +++ b/src/platform_posix.c @@ -78,24 +78,6 @@ char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname) } /* __PHYSFS_platformCopyEnvironmentVariable */ -static char *getUserNameByUID(void) -{ - uid_t uid = getuid(); - struct passwd *pw; - char *retval = NULL; - - pw = getpwuid(uid); - if ((pw != NULL) && (pw->pw_name != NULL)) - { - retval = (char *) allocator.Malloc(strlen(pw->pw_name) + 1); - if (retval != NULL) - strcpy(retval, pw->pw_name); - } /* if */ - - return retval; -} /* getUserNameByUID */ - - static char *getUserDirByUID(void) { uid_t uid = getuid(); @@ -114,15 +96,6 @@ static char *getUserDirByUID(void) } /* getUserDirByUID */ -char *__PHYSFS_platformGetUserName(void) -{ - char *retval = getUserNameByUID(); - if (retval == NULL) - retval = __PHYSFS_platformCopyEnvironmentVariable("USER"); - return retval; -} /* __PHYSFS_platformGetUserName */ - - char *__PHYSFS_platformCalcUserDir(void) { char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME"); diff --git a/src/platform_windows.c b/src/platform_windows.c index 3c7eb8b..d5493ac 100644 --- a/src/platform_windows.c +++ b/src/platform_windows.c @@ -416,26 +416,6 @@ char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app) } /* __PHYSFS_platformCalcPrefDir */ -char *__PHYSFS_platformGetUserName(void) -{ - DWORD bufsize = 0; - char *retval = NULL; - - if (GetUserNameW(NULL, &bufsize) == 0) /* This SHOULD fail. */ - { - LPWSTR wbuf = (LPWSTR) __PHYSFS_smallAlloc(bufsize * sizeof (WCHAR)); - BAIL_IF_MACRO(!wbuf, PHYSFS_ERR_OUT_OF_MEMORY, NULL); - if (GetUserNameW(wbuf, &bufsize) == 0) /* ?! */ - __PHYSFS_setError(errcodeFromWinApi()); - else - retval = unicodeToUtf8Heap(wbuf); - __PHYSFS_smallFree(wbuf); - } /* if */ - - return retval; -} /* __PHYSFS_platformGetUserName */ - - char *__PHYSFS_platformCalcUserDir(void) { typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);