Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to getpwuid() if $HOME is unset #562

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
fabiangreffrath marked this conversation as resolved.
Show resolved Hide resolved
else
#endif
home = "/";
}

// First, try legacy directory.
Expand Down
Loading