10941
|
1 # wcsrtombs.m4 serial 1 |
|
2 dnl Copyright (C) 2008 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. |
|
6 |
|
7 AC_DEFUN([gl_FUNC_WCSRTOMBS], |
|
8 [ |
|
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) |
|
10 |
|
11 AC_REQUIRE([AC_TYPE_MBSTATE_T]) |
|
12 AC_CHECK_FUNCS_ONCE([wcsrtombs]) |
|
13 if test $ac_cv_func_wcsrtombs = no; then |
|
14 HAVE_WCSRTOMBS=0 |
|
15 else |
|
16 gl_WCSRTOMBS_TERMINATION |
|
17 gl_WCSRTOMBS_NULL |
|
18 case "$gl_cv_func_wcsrtombs_termination" in |
|
19 *yes) ;; |
|
20 *) AC_DEFINE([WCSRTOMBS_TERMINATION_BUG], [1], |
|
21 [Define if the wcsrtombs function may set the source pointer to NULL without NUL-terminating the destination.]) |
|
22 REPLACE_WCSRTOMBS=1 ;; |
|
23 esac |
|
24 case "$gl_cv_func_wcsrtombs_null" in |
|
25 *yes) ;; |
|
26 *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1], |
|
27 [Define if the wcsrtombs function has the NULL destination argument bug.]) |
|
28 REPLACE_WCSRTOMBS=1 ;; |
|
29 esac |
|
30 fi |
|
31 if test $HAVE_WCSRTOMBS = 0 || test $REPLACE_WCSRTOMBS = 1; then |
|
32 gl_REPLACE_WCHAR_H |
|
33 AC_LIBOBJ([wcsrtombs]) |
|
34 gl_PREREQ_WCSRTOMBS |
|
35 fi |
|
36 ]) |
|
37 |
|
38 dnl Test whether the wcsrtombs implementation stores a non-NULL source pointer |
|
39 dnl as long as it has not written the final NUL byte to the destination string. |
|
40 dnl The OSF/1 5.1 implementation stores a NULL pointer already after storing |
|
41 dnl the last non-NUL character, even if there is no more room for the |
|
42 dnl terminating NUL character. |
|
43 dnl Result is gl_cv_func_wcsrtombs_termination. |
|
44 |
|
45 AC_DEFUN([gl_WCSRTOMBS_TERMINATION], |
|
46 [ |
|
47 AC_REQUIRE([AC_PROG_CC]) |
|
48 AC_REQUIRE([gt_LOCALE_FR]) |
|
49 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
|
50 AC_CACHE_CHECK([whether wcsrtombs updates the source pointer correctly], |
|
51 [gl_cv_func_wcsrtombs_termination], |
|
52 [ |
|
53 dnl Initial guess, used when cross-compiling or when no suitable locale |
|
54 dnl is present. |
|
55 changequote(,)dnl |
|
56 case "$host_os" in |
|
57 # Guess no on OSF/1. |
|
58 osf*) gl_cv_func_wcsrtombs_termination="guessing no" ;; |
|
59 # Guess yes otherwise. |
|
60 *) gl_cv_func_wcsrtombs_termination="guessing yes" ;; |
|
61 esac |
|
62 changequote([,])dnl |
|
63 if test $LOCALE_FR != none; then |
|
64 AC_TRY_RUN([ |
|
65 #include <locale.h> |
|
66 #include <stdlib.h> |
|
67 #include <wchar.h> |
|
68 int main () |
|
69 { |
|
70 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL) |
|
71 { |
|
72 const char original[] = "B\374\337er"; |
|
73 wchar_t input[10]; |
|
74 |
|
75 if (mbstowcs (input, original, 10) == 5) |
|
76 { |
|
77 const wchar_t *src = input; |
|
78 char output[5]; |
|
79 wcsrtombs (output, &src, 5, NULL); |
|
80 if (src != input + 5) |
|
81 return 1; |
|
82 } |
|
83 } |
|
84 return 0; |
|
85 }], |
|
86 [gl_cv_func_wcsrtombs_termination=yes], |
|
87 [gl_cv_func_wcsrtombs_termination=no], |
|
88 []) |
|
89 fi |
|
90 ]) |
|
91 ]) |
|
92 |
|
93 dnl Test whether the wcsrtombs implementation supports a NULL argument |
|
94 dnl correctly. This is not the case on HP-UX 11.11 and OSF/1 5.1: These |
|
95 dnl implementations updates the source pointer also if the destination argument |
|
96 dnl is NULL. |
|
97 dnl Result is gl_cv_func_wcsrtombs_null. |
|
98 |
|
99 AC_DEFUN([gl_WCSRTOMBS_NULL], |
|
100 [ |
|
101 AC_REQUIRE([AC_PROG_CC]) |
|
102 AC_REQUIRE([gt_LOCALE_FR]) |
|
103 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
|
104 AC_CACHE_CHECK([whether wcsrtombs supports a NULL argument correctly], |
|
105 [gl_cv_func_wcsrtombs_null], |
|
106 [ |
|
107 dnl Initial guess, used when cross-compiling or when no suitable locale |
|
108 dnl is present. |
|
109 changequote(,)dnl |
|
110 case "$host_os" in |
|
111 # Guess no on HP-UX and OSF/1. |
|
112 hpux* | osf*) gl_cv_func_wcsrtombs_null="guessing no" ;; |
|
113 # Guess yes otherwise. |
|
114 *) gl_cv_func_wcsrtombs_null="guessing yes" ;; |
|
115 esac |
|
116 changequote([,])dnl |
|
117 if test $LOCALE_FR != none; then |
|
118 AC_TRY_RUN([ |
|
119 #include <locale.h> |
|
120 #include <stdlib.h> |
|
121 #include <wchar.h> |
|
122 int main () |
|
123 { |
|
124 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL) |
|
125 { |
|
126 const char original[] = "B\374\337er"; |
|
127 wchar_t input[10]; |
|
128 |
|
129 if (mbstowcs (input, original, 10) == 5) |
|
130 { |
|
131 const wchar_t *src = input; |
|
132 wcsrtombs (NULL, &src, 10, NULL); |
|
133 if (src != input) |
|
134 return 1; |
|
135 } |
|
136 } |
|
137 return 0; |
|
138 }], |
|
139 [gl_cv_func_wcsrtombs_null=yes], |
|
140 [gl_cv_func_wcsrtombs_null=no], |
|
141 []) |
|
142 fi |
|
143 ]) |
|
144 ]) |
|
145 |
|
146 # Prerequisites of lib/wcsrtombs.c. |
|
147 AC_DEFUN([gl_PREREQ_WCSRTOMBS], [ |
|
148 : |
|
149 ]) |