2 dnl Copyright (C) 2006-2018 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], [], [], [[
22 /* AIX 3.2.5 declares wcwidth in <string.h>. */
24 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
26 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
33 if test $ac_cv_have_decl_wcwidth != yes; then
37 if test $ac_cv_func_wcwidth != yes; then
38 AC_CACHE_CHECK([whether wcwidth is a macro],
39 [gl_cv_func_wcwidth_macro],
40 [AC_EGREP_CPP([wchar_header_defines_wcwidth], [
43 wchar_header_defines_wcwidth
45 [gl_cv_func_wcwidth_macro=yes],
46 [gl_cv_func_wcwidth_macro=no])
50 if test $ac_cv_func_wcwidth = yes || test $gl_cv_func_wcwidth_macro = yes; then
52 dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
53 dnl On OpenBSD 5.0, wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
54 dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
55 dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
56 dnl This leads to bugs in 'ls' (coreutils).
57 AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
58 [gl_cv_func_wcwidth_works],
63 /* AIX 3.2.5 declares wcwidth in <string.h>. */
65 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
67 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
73 #if !HAVE_DECL_WCWIDTH
83 if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL)
85 if (wcwidth (0x0301) > 0)
87 if (wcwidth (0x05B0) > 0)
89 if (wcwidth (0x200B) > 0)
91 if (wcwidth (0xFF1A) == 0)
96 [gl_cv_func_wcwidth_works=yes],
97 [gl_cv_func_wcwidth_works=no],
101 # Guess yes on glibc and AIX 7 systems.
102 *-gnu* | gnu* | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
103 *) gl_cv_func_wcwidth_works="guessing no";;
108 case "$gl_cv_func_wcwidth_works" in
110 *no) REPLACE_WCWIDTH=1 ;;
115 dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
116 dnl have the wcwidth function, then it does not declare it.
119 # Prerequisites of lib/wcwidth.c.
120 AC_DEFUN([gl_PREREQ_WCWIDTH], [
121 AC_REQUIRE([AC_C_INLINE])