2 dnl Copyright (C) 2006-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_WCWIDTH],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 dnl Persuade glibc <wchar.h> to declare wcwidth().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15 AC_REQUIRE([gt_TYPE_WCHAR_T])
16 AC_REQUIRE([gt_TYPE_WINT_T])
18 AC_CHECK_HEADERS_ONCE([wchar.h])
19 AC_CHECK_FUNCS_ONCE([wcwidth])
21 AC_CHECK_DECLS([wcwidth], [], [], [[
24 if test $ac_cv_have_decl_wcwidth != yes; then
28 if test $ac_cv_func_wcwidth != yes; then
29 AC_CACHE_CHECK([whether wcwidth is a macro],
30 [gl_cv_func_wcwidth_macro],
31 [AC_EGREP_CPP([wchar_header_defines_wcwidth], [
34 wchar_header_defines_wcwidth
36 [gl_cv_func_wcwidth_macro=yes],
37 [gl_cv_func_wcwidth_macro=no])
41 if test $ac_cv_func_wcwidth = yes || test $gl_cv_func_wcwidth_macro = yes; then
43 dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
44 dnl On NetBSD 9.0, OpenBSD 5.0, MidnightBSD 1.1,
45 dnl wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
46 dnl On NetBSD 9.0, MidnightBSD 1.1, OSF/1 5.1,
47 dnl wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
48 dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
49 dnl This leads to bugs in 'ls' (coreutils).
50 dnl On Solaris 11.4, wcwidth(0x2202) (PARTIAL DIFFERENTIAL) returns 2,
51 dnl even in Western locales.
52 AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
53 [gl_cv_func_wcwidth_works],
59 #if !HAVE_DECL_WCWIDTH
69 if (setlocale (LC_ALL, "en_US.UTF-8") != NULL)
71 if (wcwidth (0x0301) > 0)
73 if (wcwidth (0x05B0) > 0)
75 if (wcwidth (0x200B) > 0)
77 if (wcwidth (0xFF1A) == 0)
79 if (wcwidth (0x2202) > 1)
84 [gl_cv_func_wcwidth_works=yes],
85 [gl_cv_func_wcwidth_works=no],
89 # Guess yes on glibc systems.
90 *-gnu* | gnu*) gl_cv_func_wcwidth_works="guessing yes";;
91 # Guess yes on musl systems.
92 *-musl*) gl_cv_func_wcwidth_works="guessing yes";;
93 # Guess yes on AIX 7 systems.
94 aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
95 *) gl_cv_func_wcwidth_works="$gl_cross_guess_normal";;
100 case "$gl_cv_func_wcwidth_works" in
102 *no) REPLACE_WCWIDTH=1 ;;
107 dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
108 dnl have the wcwidth function, then it does not declare it.
111 # Prerequisites of lib/wcwidth.c.
112 AC_DEFUN([gl_PREREQ_WCWIDTH], [
113 AC_REQUIRE([AC_C_INLINE])