The previous code would cause failures to find the Compose file if one
of the environment variables LC_ALL, LC_CTYPE or LANG are set to the
empty string.
The description of the fallback procedure in loclale(7) talks about
"non-null environment variable"; I interpreted this to mean the
environment variable is unset, but it actually means unset or empty (I
verified this by looking at what glibc and musl do).
A recent bug in systemd https://github.com/systemd/systemd/issues/6407
exposed this issue. It causes these these variables to be set to the
empty string in TTY sessions.
Reported by "doodoo" in https://bbs.archlinux.org/viewtopic.php?id=228658
Signed-off-by: Ran Benita <ran234@gmail.com>
* you may nevertheless obtain the user's locale directly using
* environment variables, as described in locale(7). For example,
* @code
+ * const char *locale;
* locale = getenv("LC_ALL");
- * if (!locale)
+ * if (!locale || !*locale)
* locale = getenv("LC_CTYPE");
- * if (!locale)
+ * if (!locale || !*locale)
* locale = getenv("LANG");
- * if (!locale)
+ * if (!locale || !*locale)
* locale = "C";
* @endcode
*