From 73c99b6015be51f912cb12c338bd9706b2b27992 Mon Sep 17 00:00:00 2001 From: suve Date: Sun, 22 Dec 2024 14:44:44 +0100 Subject: [PATCH] Fallback to getpwuid() if $HOME is unset This commit makes the game fallback to using getpwuid() for retrieving information about the user's home directory, should $HOME be unset. --- prboom2/CMakeLists.txt | 1 + prboom2/cmake/config.h.cin | 1 + prboom2/src/SDL/i_system.c | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/prboom2/CMakeLists.txt b/prboom2/CMakeLists.txt index 5688979eb..0d60ad7c4 100644 --- a/prboom2/CMakeLists.txt +++ b/prboom2/CMakeLists.txt @@ -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) diff --git a/prboom2/cmake/config.h.cin b/prboom2/cmake/config.h.cin index cf22db982..f24fb1e52 100644 --- a/prboom2/cmake/config.h.cin +++ b/prboom2/cmake/config.h.cin @@ -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 diff --git a/prboom2/src/SDL/i_system.c b/prboom2/src/SDL/i_system.c index c1a86e84e..9d70c8c94 100644 --- a/prboom2/src/SDL/i_system.c +++ b/prboom2/src/SDL/i_system.c @@ -56,6 +56,10 @@ #ifdef HAVE_UNISTD_H #include +#ifdef HAVE_GETPWUID +#include +#include +#endif #endif #ifdef _MSC_VER @@ -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.