Skip to content

Commit

Permalink
Fallback to getpwuid() if $HOME is unset
Browse files Browse the repository at this point in the history
This commit makes the game fallback to using getpwuid() for retrieving
information about the user's home directory, should $HOME be unset.
  • Loading branch information
suve committed Dec 22, 2024
1 parent e833ce5 commit 136ce7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prboom2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)

include(CheckIncludeFile)

check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("pwd.h" HAVE_PWD_H)
check_include_file("asm/byteorder.h" HAVE_ASM_BYTEORDER_H)
check_include_file("dirent.h" HAVE_DIRENT_H)

Expand Down
2 changes: 2 additions & 0 deletions prboom2/cmake/config.h.cin
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#cmakedefine HAVE_STRSIGNAL
#cmakedefine HAVE_MKSTEMP

#cmakedefine HAVE_SYS_TYPES_H
#cmakedefine HAVE_SYS_WAIT_H
#cmakedefine HAVE_UNISTD_H
#cmakedefine HAVE_PWD_H
#cmakedefine HAVE_ASM_BYTEORDER_H
#cmakedefine HAVE_DIRENT_H

Expand Down
14 changes: 14 additions & 0 deletions prboom2/src/SDL/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#ifdef HAVE_PWD_H
#ifdef HAVE_SYS_TYPES_H
#include <pwd.h>
#include <sys/types.h>
#define GETPWUID_FALLBACK
#endif
#endif
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -316,6 +323,13 @@ const char *I_ConfigDir(void)
if (!home)
{
home = "/";

#ifdef GETPWUID_FALLBACK
struct passwd *user_info = getpwuid(getuid());
if (user_info != NULL) {
home = user_info->pw_dir;
}
#endif
}

// First, try legacy directory.
Expand Down

0 comments on commit 136ce7b

Please sign in to comment.