From 9f5c0c361e36917483e5fce6d407804f61a1b603 Mon Sep 17 00:00:00 2001 From: John Zaitseff <J.Zaitseff@zap.org.au> Date: Mon, 1 Aug 2022 11:37:28 +1000 Subject: [PATCH] Fix bug when the HOME environment variable is empty --- NEWS | 3 +++ src/utils.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index a69679b..8979d37 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,9 @@ __ https://www.zap.org.au/ Version 7.17 (not yet released) ------------------------------- +Fixed a bug when the ``HOME`` environment variable is empty: use the +current directory instead. + Updated the Brazilian Portuguese, Norwegian Bokmål, Swedish, French, Esperanto, Serbian, German and English translations (in that order), with thanks to Rafael Fontenelle, Johnny A. Solbu, Anders Jonsson, Frédéric diff --git a/src/utils.c b/src/utils.c index a209b56..3a30080 100644 --- a/src/utils.c +++ b/src/utils.c @@ -56,6 +56,7 @@ wchar_t *mon_thousands_sep; // Locale's monetary thousands separator #define APPIMAGE_NAME "AppRun.wrapped" #define DIRSEP "/" // Directory separator +#define CURDIR "." // Current directory #define HIDDEN_PATH "." // Hidden file start char #define XDG_DATA_DEFAULT ".local" DIRSEP "share" @@ -314,7 +315,8 @@ static ssize_t b64decode (const void *restrict in, size_t inlen, * Initialisation and environment function definitions * ************************************************************************/ -// These functions are documented in the file "utils.h" +/* These functions are documented in the file "utils.h" or in the + comments above. */ /***********************************************************************/ @@ -361,6 +363,8 @@ const char *home_directory (void) if (home != NULL && *home != '\0') { home_directory_str = xstrdup(home); + } else { + home_directory_str = xstrdup(CURDIR); } }