summaryrefslogtreecommitdiffstats
path: root/gl/m4/wcwidth.m4
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-12-28 12:13:40 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-12-28 12:13:40 +0100
commitb0afb8fe0ff1d87165af9df61501197a06240dda (patch)
tree274ac6a96c53ef4c19ab4974ce24a06a233128c5 /gl/m4/wcwidth.m4
parent68fc05381ee5fa0aee1413118fbb3d81ca888b09 (diff)
downloadmonitoring-plugins-b0afb8fe0ff1d87165af9df61501197a06240dda.tar.gz
Sync with Gnulib stable-202507 code (a8ac9f9ce5)
Diffstat (limited to 'gl/m4/wcwidth.m4')
-rw-r--r--gl/m4/wcwidth.m4116
1 files changed, 116 insertions, 0 deletions
diff --git a/gl/m4/wcwidth.m4 b/gl/m4/wcwidth.m4
new file mode 100644
index 00000000..2cc6ebb1
--- /dev/null
+++ b/gl/m4/wcwidth.m4
@@ -0,0 +1,116 @@
1# wcwidth.m4
2# serial 38
3dnl Copyright (C) 2006-2025 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
8
9AC_DEFUN([gl_FUNC_WCWIDTH],
10[
11 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13
14 dnl Persuade glibc <wchar.h> to declare wcwidth().
15 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16
17 AC_REQUIRE([gt_TYPE_WINT_T])
18
19 AC_CHECK_HEADERS_ONCE([wchar.h])
20 AC_CHECK_FUNCS_ONCE([wcwidth])
21
22 AC_CHECK_DECLS([wcwidth], [], [], [[
23 #include <wchar.h>
24 ]])
25 if test $ac_cv_have_decl_wcwidth != yes; then
26 HAVE_DECL_WCWIDTH=0
27 fi
28
29 if test $ac_cv_func_wcwidth != yes; then
30 AC_CACHE_CHECK([whether wcwidth is a macro],
31 [gl_cv_func_wcwidth_macro],
32 [AC_EGREP_CPP([wchar_header_defines_wcwidth], [
33#include <wchar.h>
34#ifdef wcwidth
35 wchar_header_defines_wcwidth
36#endif],
37 [gl_cv_func_wcwidth_macro=yes],
38 [gl_cv_func_wcwidth_macro=no])
39 ])
40 fi
41
42 if test $ac_cv_func_wcwidth = yes || test $gl_cv_func_wcwidth_macro = yes; then
43 HAVE_WCWIDTH=1
44 dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
45 dnl On macOS 12.5, NetBSD 9.3, OpenBSD 5.0, MidnightBSD 1.1,
46 dnl wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
47 dnl On macOS 12.5, NetBSD 9.3, MidnightBSD 1.1, OSF/1 5.1,
48 dnl wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
49 dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
50 dnl This leads to bugs in 'ls' (coreutils).
51 dnl On Solaris 11.4, wcwidth(0x2202) (PARTIAL DIFFERENTIAL) returns 2,
52 dnl even in Western locales.
53 AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
54 [gl_cv_func_wcwidth_works],
55 [
56 AC_RUN_IFELSE(
57 [AC_LANG_SOURCE([[
58#include <locale.h>
59#include <wchar.h>
60#if !HAVE_DECL_WCWIDTH
61extern
62# ifdef __cplusplus
63"C"
64# endif
65int wcwidth (int);
66#endif
67int main ()
68{
69 int result = 0;
70 if (setlocale (LC_ALL, "en_US.UTF-8") != NULL)
71 {
72 if (wcwidth (0x0301) > 0)
73 result |= 1;
74 if (wcwidth (0x05B0) > 0)
75 result |= 2;
76 if (wcwidth (0x200B) > 0)
77 result |= 4;
78 if (wcwidth (0xFF1A) == 0)
79 result |= 8;
80 if (wcwidth (0x2202) > 1)
81 result |= 16;
82 }
83 return result;
84}]])],
85 [gl_cv_func_wcwidth_works=yes],
86 [gl_cv_func_wcwidth_works=no],
87 [
88changequote(,)dnl
89 case "$host_os" in
90 # Guess yes on glibc systems.
91 *-gnu* | gnu*) gl_cv_func_wcwidth_works="guessing yes";;
92 # Guess yes on musl systems.
93 *-musl* | midipix*) gl_cv_func_wcwidth_works="guessing yes";;
94 # Guess yes on AIX 7 systems.
95 aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
96 *) gl_cv_func_wcwidth_works="$gl_cross_guess_normal";;
97 esac
98changequote([,])dnl
99 ])
100 ])
101 case "$gl_cv_func_wcwidth_works" in
102 *yes) ;;
103 *no) REPLACE_WCWIDTH=1 ;;
104 esac
105 else
106 HAVE_WCWIDTH=0
107 fi
108 dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
109 dnl have the wcwidth function, then it does not declare it.
110])
111
112# Prerequisites of lib/wcwidth.c.
113AC_DEFUN([gl_PREREQ_WCWIDTH], [
114 AC_REQUIRE([AC_C_INLINE])
115 :
116])