Skip to content

Commit

Permalink
Removed fallback for systems that have no userdir.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
icculus committed Mar 22, 2012
1 parent b1d4afc commit a0af6bb
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 77 deletions.
24 changes: 1 addition & 23 deletions src/physfs.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions src/physfs_internal.h
Expand Up @@ -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,
Expand Down
27 changes: 0 additions & 27 deletions src/platform_posix.c
Expand Up @@ -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();
Expand All @@ -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");
Expand Down
20 changes: 0 additions & 20 deletions src/platform_windows.c
Expand Up @@ -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);
Expand Down

0 comments on commit a0af6bb

Please sign in to comment.