summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac7
-rw-r--r--openbsd-compat/bsd-misc.c17
-rw-r--r--openbsd-compat/openbsd-compat.h18
3 files changed, 41 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 005a9ead5..f6c44b874 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1721,7 +1721,6 @@ AC_CHECK_FUNCS([ \
1721 inet_ntop \ 1721 inet_ntop \
1722 innetgr \ 1722 innetgr \
1723 login_getcapbool \ 1723 login_getcapbool \
1724 mblen \
1725 md5_crypt \ 1724 md5_crypt \
1726 memmove \ 1725 memmove \
1727 memset_s \ 1726 memset_s \
@@ -1789,6 +1788,12 @@ AC_CHECK_FUNCS([ \
1789 warn \ 1788 warn \
1790]) 1789])
1791 1790
1791dnl Wide character support. Linux man page says it needs _XOPEN_SOURCE.
1792saved_CFLAGS="$CFLAGS"
1793CFLAGS="$CFLAGS -D_XOPEN_SOURCE"
1794AC_CHECK_FUNCS([mblen mbtowc nl_langinfo wcwidth])
1795CFLAGS="$saved_CFLAGS"
1796
1792AC_LINK_IFELSE( 1797AC_LINK_IFELSE(
1793 [AC_LANG_PROGRAM( 1798 [AC_LANG_PROGRAM(
1794 [[ #include <ctype.h> ]], 1799 [[ #include <ctype.h> ]],
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 2a788e47f..18bf62dd8 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -284,3 +284,20 @@ pledge(const char *promises, const char *paths[])
284 return 0; 284 return 0;
285} 285}
286#endif 286#endif
287
288#ifndef HAVE_MBTOWC
289/* a mbtowc that only supports ASCII */
290int
291mbtowc(wchar_t *pwc, const char *s, size_t n)
292{
293 if (s == NULL || *s == '\0')
294 return 0; /* ASCII is not state-dependent */
295 if (*s < 0 || *s > 0x7f || n < 1) {
296 errno = EOPNOTSUPP;
297 return -1;
298 }
299 if (pwc != NULL)
300 *pwc = *s;
301 return 1;
302}
303#endif
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 8cc8a11b7..997541e43 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -36,6 +36,8 @@
36 36
37#include <sys/socket.h> 37#include <sys/socket.h>
38 38
39#include <stddef.h> /* for wchar_t */
40
39/* OpenBSD function replacements */ 41/* OpenBSD function replacements */
40#include "base64.h" 42#include "base64.h"
41#include "sigact.h" 43#include "sigact.h"
@@ -231,6 +233,22 @@ long long strtonum(const char *, long long, long long, const char **);
231# define mblen(x, y) (1) 233# define mblen(x, y) (1)
232#endif 234#endif
233 235
236#ifndef HAVE_WCWIDTH
237# define wcwidth(x) (((x) >= 0x20 && (x) <= 0x7e) ? 1 : -1)
238/* force our no-op nl_langinfo and mbtowc */
239# undef HAVE_NL_LANGINFO
240# undef HAVE_MBTOWC
241# undef HAVE_LANGINFO_H
242#endif
243
244#ifndef HAVE_NL_LANGINFO
245# define nl_langinfo(x) ""
246#endif
247
248#ifndef HAVE_MBTOWC
249int mbtowc(wchar_t *, const char*, size_t);
250#endif
251
234#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) 252#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
235# include <stdarg.h> 253# include <stdarg.h>
236#endif 254#endif