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