aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/termkey.c b/termkey.c
index 8a73683..db084cc 100644
--- a/termkey.c
+++ b/termkey.c
@@ -6,9 +6,12 @@
#include <poll.h>
#include <unistd.h>
#include <string.h>
+#include <strings.h>
#include <stdio.h>
+#define strcaseeq(a,b) (strcasecmp(a,b) == 0)
+
void termkey_check_version(int major, int minor)
{
if(major != TERMKEY_VERSION_MAJOR) {
@@ -384,8 +387,12 @@ TermKey *termkey_new(int fd, int flags)
if(!(flags & (TERMKEY_FLAG_RAW|TERMKEY_FLAG_UTF8))) {
char *e;
+ /* Most OSes will set .UTF-8. Some will set .utf8. Try to be fairly
+ * generous in parsing these
+ */
if(((e = getenv("LANG")) || (e = getenv("LC_MESSAGES")) || (e = getenv("LC_ALL"))) &&
- (strstr(e, ".UTF-8") || strstr(e, ".utf8")))
+ (e = strchr(e, '.')) && e++ &&
+ (strcaseeq(e, "UTF-8") || strcaseeq(e, "UTF8")))
flags |= TERMKEY_FLAG_UTF8;
else
flags |= TERMKEY_FLAG_RAW;