From 932341f0e65f369772b46981ba3de63124c86980 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Thu, 12 Mar 2015 12:38:17 -0400 Subject: [PATCH] Better method of finding the user home directory. --- src/init.cpp | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index e42a048..e628212 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -19,7 +19,7 @@ along with this program. If not, see . #include "Starfighter.h" -#include +#include #include #include #include @@ -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 -home directory, then creates the .parallelrealities and .parallelrealities/starfighter -directories so that saves and temporary data files can be written there. Good, eh? :) +This gets the user's home directory, then creates the .parallelrealities +and .parallelrealities/starfighter directories so that saves and +temporary data files can be written there. */ static void setupUserHomeDirectory() { - char *userHome; + const char *userHome; - char *name = getlogin(); - - 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; + if ((userHome = getenv("HOME")) == NULL) + userHome = getpwuid(getuid())->pw_dir; char dir[PATH_MAX]; strcpy(dir, "");