summaryrefslogtreecommitdiffstats
path: root/term_ascii.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-04-13 18:31:00 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-04-13 18:31:00 +0000
commit0b240988cde7a037bb883093149affbf412551d4 (patch)
treea50e9dea95e830bde24014debe1c77597e53c8f5 /term_ascii.c
parent534cdc68f3485e735d3ad600a0eae1623a2b15d1 (diff)
downloadmandoc-0b240988cde7a037bb883093149affbf412551d4.tar.gz
Make sure that mandoc only goes into UTF-8 mode if the user really
selected UTF-8, not some other multibyte locale. This obviously makes no difference on OpenBSD but improves portability. Issue reported by <Nakayama at NetBSD> via wiz@.
Diffstat (limited to 'term_ascii.c')
-rw-r--r--term_ascii.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/term_ascii.c b/term_ascii.c
index 8e8e3b41..203042c5 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -21,11 +21,13 @@
#include <assert.h>
#if HAVE_WCHAR
+#include <langinfo.h>
#include <locale.h>
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#if HAVE_WCHAR
#include <wchar.h>
@@ -100,7 +102,17 @@ ascii_init(enum termenc enc, const struct manoutput *outopts)
v = TERMENC_LOCALE == enc ?
setlocale(LC_CTYPE, "") :
setlocale(LC_CTYPE, UTF8_LOCALE);
- if (NULL != v && MB_CUR_MAX > 1) {
+
+ /*
+ * We only support UTF-8,
+ * so revert to ASCII for anything else.
+ */
+
+ if (v != NULL &&
+ strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
+ v = setlocale(LC_CTYPE, "C");
+
+ if (v != NULL && MB_CUR_MAX > 1) {
p->enc = enc;
p->advance = locale_advance;
p->endline = locale_endline;