Better method of finding the user home directory.
This commit is contained in:
parent
ea33be4591
commit
932341f0e6
28
src/init.cpp
28
src/init.cpp
|
@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "Starfighter.h"
|
#include "Starfighter.h"
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -103,30 +103,16 @@ void showErrorAndExit(int errorId, const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This bit is just for Linux users. It attempts to get the user's
|
This gets the user's home directory, then creates the .parallelrealities
|
||||||
home directory, then creates the .parallelrealities and .parallelrealities/starfighter
|
and .parallelrealities/starfighter directories so that saves and
|
||||||
directories so that saves and temporary data files can be written there. Good, eh? :)
|
temporary data files can be written there.
|
||||||
*/
|
*/
|
||||||
static void setupUserHomeDirectory()
|
static void setupUserHomeDirectory()
|
||||||
{
|
{
|
||||||
char *userHome;
|
const char *userHome;
|
||||||
|
|
||||||
char *name = getlogin();
|
if ((userHome = getenv("HOME")) == NULL)
|
||||||
|
userHome = getpwuid(getuid())->pw_dir;
|
||||||
passwd *pass;
|
|
||||||
|
|
||||||
if (name != NULL)
|
|
||||||
pass = getpwnam(name);
|
|
||||||
else
|
|
||||||
pass = getpwuid(geteuid());
|
|
||||||
|
|
||||||
if (pass == NULL)
|
|
||||||
{
|
|
||||||
printf("Couldn't determine the user home directory. Exitting.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
userHome = pass->pw_dir;
|
|
||||||
|
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
strcpy(dir, "");
|
strcpy(dir, "");
|
||||||
|
|
Loading…
Reference in New Issue