1
0
Эх сурвалжийг харах

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.
Ryan C. Gordon 14 жил өмнө
parent
commit
a0af6bbb71

+ 1 - 23
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);

+ 0 - 7
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,

+ 0 - 27
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");

+ 0 - 20
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);