Skip to content

Commit

Permalink
Merge pull request #562 from suve/getpwuid-fallback
Browse files Browse the repository at this point in the history
Fallback to getpwuid() if $HOME is unset
  • Loading branch information
Pedro-Beirao authored Dec 23, 2024
2 parents 3b94adb + 73c99b6 commit fe0dfa0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions prboom2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
check_symbol_exists(CreateFileMapping "windows.h" HAVE_CREATE_FILE_MAPPING)
check_symbol_exists(strsignal "string.h" HAVE_STRSIGNAL)
check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)
check_symbol_exists(getpwuid "unistd.h;sys/types.h;pwd.h" HAVE_GETPWUID)

include(CheckIncludeFile)

Expand Down
1 change: 1 addition & 0 deletions prboom2/cmake/config.h.cin
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#cmakedefine HAVE_CREATE_FILE_MAPPING
#cmakedefine HAVE_STRSIGNAL
#cmakedefine HAVE_MKSTEMP
#cmakedefine HAVE_GETPWUID

#cmakedefine HAVE_SYS_WAIT_H
#cmakedefine HAVE_UNISTD_H
Expand Down
12 changes: 11 additions & 1 deletion prboom2/src/SDL/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#ifdef HAVE_GETPWUID
#include <sys/types.h>
#include <pwd.h>
#endif
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -315,7 +319,13 @@ const char *I_ConfigDir(void)
const char *home = M_getenv("HOME");
if (!home)
{
home = "/";
#ifdef HAVE_GETPWUID
struct passwd *user_info = getpwuid(getuid());
if (user_info != NULL)
home = user_info->pw_dir;
else
#endif
home = "/";
}

// First, try legacy directory.
Expand Down

0 comments on commit fe0dfa0

Please sign in to comment.