mbtowc: Fix compilation error on Android 4.3.
authorBruno Haible <bruno@clisp.org>
Thu, 24 Jan 2019 23:42:40 +0000 (00:42 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 25 Jan 2019 01:14:28 +0000 (02:14 +0100)
* 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.

ChangeLog
doc/posix-functions/mbtowc.texi
lib/stdlib.in.h
m4/mbtowc.m4
m4/stdlib_h.m4
modules/mbtowc
modules/stdlib

index 4955af18b7ae115aa60ac25e42497aa94ba116bb..24d57550113b1d92263660209f4462210417165c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 022e1a2d14043ff4123eee6b5f51316788f05a2c..5188a7f193e00acf673cc909d89eba918703fc5b 100644 (file)
@@ -8,14 +8,14 @@ Gnulib module: mbtowc
 
 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
index d80d7ec6b058b85aaf2d0c473c35b168a8bc4bcf..0f581d9fc509398ed7caa19b8f123855a82f88b7 100644 (file)
@@ -306,9 +306,18 @@ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
 _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@
index 202c3fbdb5616ee1ac68f98c06e27a7a0f52a7db..5a4b92ee52eb71ed263b22829ccbe8f7349d81e1 100644 (file)
@@ -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_DEFUN([gl_FUNC_MBTOWC],
 [
   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
 ])
 
index cf064284b6461c25b3cf0979b900340eb7f40166..c449a5404e0ba4c266963bc57e3439c88b3b9d84 100644 (file)
@@ -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 @@ AC_DEFUN([gl_STDLIB_H],
 # 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 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   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])
index a665e2252ac27d4222d11c41df83d84e373c53b6..2db32deb143948899b1b8a849e18f38e3902c4e8 100644 (file)
@@ -8,12 +8,12 @@ m4/mbtowc.m4
 
 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
index 62224e89f397bf6f2e9f4ece42710f688d1914e9..dd1556e4e44be149c5c052b40313199d5356d157 100644 (file)
@@ -73,6 +73,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
              -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' \