[openssh-commits] [openssh] 01/01: Add compat code for missing wcwidth.
git+noreply at mindrot.org
git+noreply at mindrot.org
Thu Jul 14 11:03:15 AEST 2016
This is an automated email from the git hooks/post-receive script.
dtucker pushed a commit to branch master
in repository openssh.
commit a2333584170a565adf4f209586772ef8053b10b8
Author: Darren Tucker <dtucker at zip.com.au>
Date: Thu Jul 14 10:59:09 2016 +1000
Add compat code for missing wcwidth.
If we don't have wcwidth force fallback implementations of nl_langinfo
and mbtowc. Based on advice from Ingo Schwarze.
---
configure.ac | 7 ++++++-
openbsd-compat/bsd-misc.c | 17 +++++++++++++++++
openbsd-compat/openbsd-compat.h | 18 ++++++++++++++++++
3 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 005a9ea..f6c44b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1721,7 +1721,6 @@ AC_CHECK_FUNCS([ \
inet_ntop \
innetgr \
login_getcapbool \
- mblen \
md5_crypt \
memmove \
memset_s \
@@ -1789,6 +1788,12 @@ AC_CHECK_FUNCS([ \
warn \
])
+dnl Wide character support. Linux man page says it needs _XOPEN_SOURCE.
+saved_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -D_XOPEN_SOURCE"
+AC_CHECK_FUNCS([mblen mbtowc nl_langinfo wcwidth])
+CFLAGS="$saved_CFLAGS"
+
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[ #include <ctype.h> ]],
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 2a788e4..18bf62d 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -284,3 +284,20 @@ pledge(const char *promises, const char *paths[])
return 0;
}
#endif
+
+#ifndef HAVE_MBTOWC
+/* a mbtowc that only supports ASCII */
+int
+mbtowc(wchar_t *pwc, const char *s, size_t n)
+{
+ if (s == NULL || *s == '\0')
+ return 0; /* ASCII is not state-dependent */
+ if (*s < 0 || *s > 0x7f || n < 1) {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
+ if (pwc != NULL)
+ *pwc = *s;
+ return 1;
+}
+#endif
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 8cc8a11..997541e 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -36,6 +36,8 @@
#include <sys/socket.h>
+#include <stddef.h> /* for wchar_t */
+
/* OpenBSD function replacements */
#include "base64.h"
#include "sigact.h"
@@ -231,6 +233,22 @@ long long strtonum(const char *, long long, long long, const char **);
# define mblen(x, y) (1)
#endif
+#ifndef HAVE_WCWIDTH
+# define wcwidth(x) (((x) >= 0x20 && (x) <= 0x7e) ? 1 : -1)
+/* force our no-op nl_langinfo and mbtowc */
+# undef HAVE_NL_LANGINFO
+# undef HAVE_MBTOWC
+# undef HAVE_LANGINFO_H
+#endif
+
+#ifndef HAVE_NL_LANGINFO
+# define nl_langinfo(x) ""
+#endif
+
+#ifndef HAVE_MBTOWC
+int mbtowc(wchar_t *, const char*, size_t);
+#endif
+
#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
# include <stdarg.h>
#endif
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list