Commit f468f0b2430e15cc262c5745445580bd0dc64ef0

Ran Benita 2017-08-13T17:55:45

xkbcommon-compose.h: change recommended locale fallback code to treat empty string same as unset 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>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/xkbcommon/xkbcommon-compose.h b/xkbcommon/xkbcommon-compose.h
index 81b0d3f..25894b9 100644
--- a/xkbcommon/xkbcommon-compose.h
+++ b/xkbcommon/xkbcommon-compose.h
@@ -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
  *