aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit44b03451934776b1030c9d5109114e98520bb4c2 (patch)
treed9ab37395c6ef3c091bf28eac5033b180afbfff7
parent0c8f9a78c144e759fc8ce4b1b92b1787474385bd (diff)
downloadmandoc-44b03451934776b1030c9d5109114e98520bb4c2.tar.gz
mandoc-44b03451934776b1030c9d5109114e98520bb4c2.tar.zst
mandoc-44b03451934776b1030c9d5109114e98520bb4c2.zip
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@.
-rw-r--r--term_ascii.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/term_ascii.c b/term_ascii.c
index 265baf5d..43905634 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -1,7 +1,7 @@
-/* $Id: term_ascii.c,v 1.59 2017/08/23 10:50:15 schwarze Exp $ */
+/* $Id: term_ascii.c,v 1.60 2018/04/13 18:31:00 schwarze Exp $ */
/*
* 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;