From 75a3c8cd735c9de51dff542e8ebdc9a95c3f73e6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 14 Apr 2022 21:24:27 +0300 Subject: [PATCH 50/50] user_home_dir(): Improve handling of environment variables On Windows: - Do not get HOME at all, as the value was discarded anyway - Refer to correct variable in log messages See osdn #44212 Signed-off-by: Marko Lindqvist --- utility/shared.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utility/shared.c b/utility/shared.c index a9cae0b31a..ea968a0335 100644 --- a/utility/shared.c +++ b/utility/shared.c @@ -631,18 +631,20 @@ char *user_home_dir(void) return "PROGDIR:"; #else /* AMIGA */ - if (home_dir_user == NULL) { - char *env = getenv("HOME"); - #ifdef FREECIV_MSWINDOWS - env = getenv("APPDATA"); -#endif /* FREECIV_MSWINDOWS */ +#define HOMEVAR "APPDATA" +#else +#define HOMEVAR "HOME" +#endif + + if (home_dir_user == NULL) { + char *env = getenv(HOMEVAR); if (env) { home_dir_user = fc_strdup(env); - log_verbose("HOME is %s", home_dir_user); + log_verbose(HOMEVAR " is %s", home_dir_user); } else { - log_error("Could not find home directory (HOME is not set)."); + log_error("Could not find home directory (" HOMEVAR " is not set)."); home_dir_user = NULL; } } -- 2.35.1