xkbcommon-compose.h: change recommended locale fallback code to treat empty string...
authorRan Benita <ran234@gmail.com>
Sun, 13 Aug 2017 14:55:45 +0000 (17:55 +0300)
committerRan Benita <ran234@gmail.com>
Sun, 13 Aug 2017 15:03:57 +0000 (18:03 +0300)
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>
xkbcommon/xkbcommon-compose.h

index 81b0d3f..25894b9 100644 (file)
@@ -180,12 +180,13 @@ enum xkb_compose_format {
  * 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
  *