changeset 40133:11b97647fb11

mbtowc: Fix compilation error on Android 4.3. * lib/stdlib.in.h (mbtowc): Test also HAVE_MBTOWC. * m4/mbtowc.m4 (gl_FUNC_MBTOWC): Test whether mbtowc exists. Set HAVE_MBTOWC. * m4/stdlib_h.m4 (gl_STDLIB_H): Test whether mbtowc is declared. (gl_STDLIB_H_DEFAULTS): Initialize HAVE_MBTOWC. * modules/stdlib (Makefile.am): Substitute HAVE_MBTOWC. * modules/mbtowc (Depends-on, configure.ac): Test also HAVE_MBTOWC. * doc/posix-functions/mbtowc.texi: Mention the change.
author Bruno Haible <bruno@clisp.org>
date Fri, 25 Jan 2019 00:42:40 +0100
parents 6bcaf5dcb02b
children cfcc57a4ed05
files ChangeLog doc/posix-functions/mbtowc.texi lib/stdlib.in.h m4/mbtowc.m4 m4/stdlib_h.m4 modules/mbtowc modules/stdlib
diffstat 7 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jan 25 00:15:50 2019 +0100
+++ b/ChangeLog	Fri Jan 25 00:42:40 2019 +0100
@@ -1,3 +1,15 @@
+2019-01-24  Bruno Haible  <bruno@clisp.org>
+
+	mbtowc: Fix compilation error on Android 4.3.
+	* lib/stdlib.in.h (mbtowc): Test also HAVE_MBTOWC.
+	* m4/mbtowc.m4 (gl_FUNC_MBTOWC): Test whether mbtowc exists. Set
+	HAVE_MBTOWC.
+	* m4/stdlib_h.m4 (gl_STDLIB_H): Test whether mbtowc is declared.
+	(gl_STDLIB_H_DEFAULTS): Initialize HAVE_MBTOWC.
+	* modules/stdlib (Makefile.am): Substitute HAVE_MBTOWC.
+	* modules/mbtowc (Depends-on, configure.ac): Test also HAVE_MBTOWC.
+	* doc/posix-functions/mbtowc.texi: Mention the change.
+
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
 	fdatasync: Fix compilation error on Android 4.3.
--- a/doc/posix-functions/mbtowc.texi	Fri Jan 25 00:15:50 2019 +0100
+++ b/doc/posix-functions/mbtowc.texi	Fri Jan 25 00:42:40 2019 +0100
@@ -8,14 +8,14 @@
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Android 4.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-Android 4.4.
-@item
 This function accumulates hidden state on some platforms:
 glibc 2.8 (see @url{https://sourceware.org/bugzilla/show_bug.cgi?id=9674}).
 @item
--- a/lib/stdlib.in.h	Fri Jan 25 00:15:50 2019 +0100
+++ b/lib/stdlib.in.h	Fri Jan 25 00:42:40 2019 +0100
@@ -306,9 +306,18 @@
 _GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
 _GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
 # else
+#  if !@HAVE_MBTOWC@
+_GL_FUNCDECL_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
+#  endif
 _GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
 # endif
 _GL_CXXALIASWARN (mbtowc);
+#elif defined GNULIB_POSIXCHECK
+# undef mbtowc
+# if HAVE_RAW_DECL_MBTOWC
+_GL_WARN_ON_USE (mbtowc, "mbtowc is not portable - "
+                 "use gnulib module mbtowc for portability");
+# endif
 #endif
 
 #if @GNULIB_MKDTEMP@
--- a/m4/mbtowc.m4	Fri Jan 25 00:15:50 2019 +0100
+++ b/m4/mbtowc.m4	Fri Jan 25 00:42:40 2019 +0100
@@ -1,4 +1,4 @@
-# mbtowc.m4 serial 2
+# mbtowc.m4 serial 3
 dnl Copyright (C) 2011-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,8 +8,13 @@
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
 
-  if false; then
-    REPLACE_MBTOWC=1
+  AC_CHECK_FUNCS([mbtowc])
+  if test $ac_cv_func_mbtowc = no; then
+    HAVE_MBTOWC=0
+  else
+    if false; then
+      REPLACE_MBTOWC=1
+    fi
   fi
 ])
 
--- a/m4/stdlib_h.m4	Fri Jan 25 00:15:50 2019 +0100
+++ b/m4/stdlib_h.m4	Fri Jan 25 00:42:40 2019 +0100
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 45
+# stdlib_h.m4 serial 46
 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -23,7 +23,7 @@
 # include <random.h>
 #endif
     ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt
-    initstate initstate_r mkdtemp mkostemp mkostemps mkstemp mkstemps
+    initstate initstate_r mbtowc mkdtemp mkostemp mkostemps mkstemp mkstemps
     posix_openpt ptsname ptsname_r qsort_r random random_r reallocarray
     realpath rpmatch secure_getenv setenv setstate setstate_r srandom
     srandom_r strtod strtoll strtoull unlockpt unsetenv])
@@ -82,6 +82,7 @@
   HAVE_GETSUBOPT=1;          AC_SUBST([HAVE_GETSUBOPT])
   HAVE_GRANTPT=1;            AC_SUBST([HAVE_GRANTPT])
   HAVE_DECL_INITSTATE=1;     AC_SUBST([HAVE_DECL_INITSTATE])
+  HAVE_MBTOWC=1;             AC_SUBST([HAVE_MBTOWC])
   HAVE_MKDTEMP=1;            AC_SUBST([HAVE_MKDTEMP])
   HAVE_MKOSTEMP=1;           AC_SUBST([HAVE_MKOSTEMP])
   HAVE_MKOSTEMPS=1;          AC_SUBST([HAVE_MKOSTEMPS])
--- a/modules/mbtowc	Fri Jan 25 00:15:50 2019 +0100
+++ b/modules/mbtowc	Fri Jan 25 00:42:40 2019 +0100
@@ -8,12 +8,12 @@
 
 Depends-on:
 stdlib
-mbrtowc         [test $REPLACE_MBTOWC = 1]
-wchar           [test $REPLACE_MBTOWC = 1]
+mbrtowc         [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1]
+wchar           [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1]
 
 configure.ac:
 gl_FUNC_MBTOWC
-if test $REPLACE_MBTOWC = 1; then
+if test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1; then
   AC_LIBOBJ([mbtowc])
   gl_PREREQ_MBTOWC
 fi
--- a/modules/stdlib	Fri Jan 25 00:15:50 2019 +0100
+++ b/modules/stdlib	Fri Jan 25 00:42:40 2019 +0100
@@ -73,6 +73,7 @@
 	      -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
 	      -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
 	      -e 's|@''HAVE_DECL_INITSTATE''@|$(HAVE_DECL_INITSTATE)|g' \
+	      -e 's|@''HAVE_MBTOWC''@|$(HAVE_MBTOWC)|g' \
 	      -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
 	      -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
 	      -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \