summaryrefslogtreecommitdiff
path: root/lib/libedit
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2016-02-24 17:20:01 +0000
committerchristos <christos@NetBSD.org>2016-02-24 17:20:01 +0000
commit2918e3cf14d032cebc8190313e4be22aa37f0c73 (patch)
tree9649ccfa7f171d7b69e3027e44868a8fe24266c2 /lib/libedit
parentb2b6a38fcd5e124dcdc5e366298c40502b957a3d (diff)
Tuck in mbstate_t to the wide char version only to avoid exposing the zeroing
hack and doing it in the narrow case.
Diffstat (limited to 'lib/libedit')
-rw-r--r--lib/libedit/chartype.c17
-rw-r--r--lib/libedit/chartype.h7
-rw-r--r--lib/libedit/read.c9
3 files changed, 18 insertions, 15 deletions
diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c
index 148ecaeefb5..ca2dc6c5f25 100644
--- a/lib/libedit/chartype.c
+++ b/lib/libedit/chartype.c
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.c,v 1.21 2016/02/24 17:13:22 christos Exp $ */
+/* $NetBSD: chartype.c,v 1.22 2016/02/24 17:20:01 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.21 2016/02/24 17:13:22 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.22 2016/02/24 17:20:01 christos Exp $");
#endif /* not lint && not SCCSID */
#include <ctype.h>
@@ -215,12 +215,19 @@ ct_encode_char(char *dst, size_t len, Char c)
return l;
}
+size_t
+ct_mbrtowc(wchar_t *wc, const char *s, size_t n)
+{
+ mbstate_t mbs;
+ /* This only works because UTF-8 is stateless */
+ memset(&mbs, 0, sizeof(mbs));
+ return mbrtowc(wc, s, n, &mbs);
+}
+
#else
size_t
-/*ARGSUSED*/
-ct_mbrtowc(wchar_t *wc, const char *s, size_t n,
- void *mbs __attribute__((__unused__))) {
+ct_mbrtowc(wchar_t *wc, const char *s, size_t n)
if (s == NULL)
return 0;
if (n == 0)
diff --git a/lib/libedit/chartype.h b/lib/libedit/chartype.h
index aab3a0e78c4..6bbf99da810 100644
--- a/lib/libedit/chartype.h
+++ b/lib/libedit/chartype.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.h,v 1.22 2016/02/24 17:13:22 christos Exp $ */
+/* $NetBSD: chartype.h,v 1.23 2016/02/24 17:20:01 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,6 @@
#define _h_chartype_f
-
#ifdef WIDECHAR
/* Ideally we should also test the value of the define to see if it
@@ -60,7 +59,6 @@
#warning Build environment does not support non-BMP characters
#endif
-#define ct_mbrtowc mbrtowc
#define ct_wctob wctob
#define ct_wctomb wctomb
#define ct_wctomb_reset wctomb(0,0)
@@ -113,7 +111,6 @@ Width(wchar_t c)
#else /* NARROW */
-size_t ct_mbrtowc(wchar_t *, const char *, size_t, void *);
#define ct_wctob(w) ((int)(w))
#define ct_wctomb error
#define ct_wctomb_reset
@@ -246,5 +243,7 @@ protected const Char *ct_visual_string(const Char *);
protected int ct_chr_class(Char c);
#endif
+size_t ct_mbrtowc(wchar_t *, const char *, size_t);
+
#endif /* _chartype_f */
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index 7b9a544dd9f..7b7805834d5 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.84 2016/02/24 17:13:22 christos Exp $ */
+/* $NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: read.c,v 1.84 2016/02/24 17:13:22 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -343,12 +343,9 @@ read_char(EditLine *el, wchar_t *cp)
}
for (;;) {
- mbstate_t mbs;
++cbp;
- /* This only works because UTF8 is stateless */
- memset(&mbs, 0, sizeof(mbs));
- switch (ct_mbrtowc(cp, cbuf, cbp, &mbs)) {
+ switch (ct_mbrtowc(cp, cbuf, cbp)) {
case (size_t)-1:
if (cbp > 1) {
/*