bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* fix some build errors on Android 4.3
@ 2019-01-25  1:14 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2019-01-25  1:14 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 4714 bytes --]

On Android 4.3 (native compilation environment, through the 'Terminal IDE'
app), I'm seeing a number of build errors when building testdirs.

I) There is no /bin/sh. The shell is /system/bin/sh and is available through
   $PATH. This causes problems in a couple of places. One of them is that
   all tests that are shell scripts fail with 'Bad interpreter' - because
   the test-driver installed by Automake assumes that all tests are executable,
   but all these shell scripts start with '#!/bin/sh'.

   The fix is to change gnulib-tool to tweak the test-driver, in a way that
   is suitable for gnulib (but not suitable in general).

II) The environment uses a Bionic libc whose headers declare some functions
    which are not present in libc.so.
    (In newer Bionic libcs the declarations are conditionalized depending
    on the Android level.)

1)
terminal-gcc -mandroid -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/data/data/com.spartacusrex.spartacuside/files/local/include -Wall  -g -O2 -c -o test-fchownat.o ../../gltests/test-fchownat.c
../../gltests/test-fchownat.c:24: error: 'fchownat' undeclared here (not in a function)
make[4]: *** [test-fchownat.o] Error 1

libc.so has fchownat.
It is declared in <sys/stat.h>, not in <unistd.h>.

2)
terminal-gcc -mandroid -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/data/data/com.spartacusrex.spartacuside/files/local/include -Wall  -g -O2 -c -o test-renameat.o ../../gltests/test-renameat.c
../../gltests/test-renameat.c:24: error: 'renameat' undeclared here (not in a function)
make[4]: *** [test-renameat.o] Error 1

libc.so has renameat.
It is declared in <sys/stat.h>, not in <stdio.h>.

3)
terminal-gcc -mandroid -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/data/data/com.spartacusrex.spartacuside/files/local/include -Wall  -g -O2 -c -o test-unlinkat.o ../../gltests/test-unlinkat.c
../../gltests/test-unlinkat.c:24: error: 'unlinkat' undeclared here (not in a function)
make[4]: *** [test-unlinkat.o] Error 1

libc.so has unlinkat.
It is declared in <fcntl.h>, not in <unistd.h>.

4)
terminal-gcc -mandroid -std=gnu99  -g -O2  -L/data/data/com.spartacusrex.spartacuside/files/local/lib -o test-fdatasync test-fdatasync.o libtests.a ../gllib/libgnu.a libtests.a   
test-fdatasync.o: In function `main':
/data/data/com.spartacusrex.spartacuside/files/testdir-posix/build/gltests/../../gltests/test-fdatasync.c:38: undefined reference to `fdatasync'
/data/data/com.spartacusrex.spartacuside/files/testdir-posix/build/gltests/../../gltests/test-fdatasync.c:50: undefined reference to `fdatasync'
/data/data/com.spartacusrex.spartacuside/files/testdir-posix/build/gltests/../../gltests/test-fdatasync.c:56: undefined reference to `fdatasync'
/data/data/com.spartacusrex.spartacuside/files/testdir-posix/build/gltests/../../gltests/test-fdatasync.c:63: undefined reference to `fdatasync'
test-fdatasync.o:(.debug_info+0x2fb): undefined reference to `fdatasync'
collect2: ld returned 1 exit status
make[4]: *** [test-fdatasync] Error 1

libc.so does not have fdatasync.
It is declared in <unistd.h>.

5)
terminal-gcc -mandroid -std=gnu99  -g -O2  -L/data/data/com.spartacusrex.spartacuside/files/local/lib -o test-wcrtomb test-wcrtomb.o libtests.a ../gllib/libgnu.a libtests.a  
test-wcrtomb.o: In function `check_character':
/data/data/com.spartacusrex.spartacuside/files/testdir-posix/build/gltests/../../gltests/test-wcrtomb.c:42: undefined reference to `mbtowc'
collect2: ld returned 1 exit status
make[4]: *** [test-wcrtomb] Error 1

libc.so does not have mbtowc.
It is declared in <stdlib.h>.

6)
terminal-gcc -mandroid -std=gnu99  -g -O2  -L/data/data/com.spartacusrex.spartacuside/files/local/lib -o test-random test-random.o libtests.a ../gllib/libgnu.a libtests.a  
test-random.o: In function `main':
/data/data/com.spartacusrex.spartacuside/files/testdir-posix/build/gltests/../../gltests/test-random.c:38: undefined reference to `initstate'
test-random.o:(.debug_info+0x37b): undefined reference to `initstate'
test-random.o:(.debug_info+0x3a0): undefined reference to `setstate'
collect2: ld returned 1 exit status
make[4]: *** [test-random] Error 1

libc.so does not have initstate and setstate, but has random and srandom.


All these problems are fixed through the attached patches.


[-- Attachment #2: 0001-gnulib-tool-Support-running-testdirs-on-Android.patch --]
[-- Type: text/x-patch, Size: 4510 bytes --]

From cd3b12d530aa48bd460a8795aec6da06cea595b4 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 23 Jan 2019 05:11:54 +0100
Subject: [PATCH 1/7] gnulib-tool: Support running testdirs on Android.

* build-aux/test-driver.diff: New file.
* gnulib-tool (func_create_testdir, func_create_megatestdir): Patch
build-aux/test-driver after running automake.
---
 ChangeLog                  |  7 +++++++
 build-aux/test-driver.diff | 14 ++++++++++++++
 gnulib-tool                | 40 ++++++++++++++++++++++++----------------
 3 files changed, 45 insertions(+), 16 deletions(-)
 create mode 100644 build-aux/test-driver.diff

diff --git a/ChangeLog b/ChangeLog
index a8e03c5..7ba92a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-01-23  Bruno Haible  <bruno@clisp.org>
+
+	gnulib-tool: Support running testdirs on Android.
+	* build-aux/test-driver.diff: New file.
+	* gnulib-tool (func_create_testdir, func_create_megatestdir): Patch
+	build-aux/test-driver after running automake.
+
 2019-01-23  Akim Demaille  <akim@lrde.epita.fr>
 
 	relocatable-prog: avoid warnings from Automake
diff --git a/build-aux/test-driver.diff b/build-aux/test-driver.diff
new file mode 100644
index 0000000..5f49e34
--- /dev/null
+++ b/build-aux/test-driver.diff
@@ -0,0 +1,14 @@
+--- test-driver.bak	2019-01-23 03:22:06.672283432 +0100
++++ test-driver	2019-01-23 04:23:21.201060757 +0100
+@@ -104,7 +104,10 @@
+ trap "st=143; $do_exit" 15
+ 
+ # Test script is run here.
+-"$@" >$log_file 2>&1
++case "$1" in
++  *.sh) sh "$@" >$log_file 2>&1 ;;
++  *)    "$@" >$log_file 2>&1 ;;
++esac
+ estatus=$?
+ 
+ if test $enable_hard_errors = no && test $estatus -eq 99; then
diff --git a/gnulib-tool b/gnulib-tool
index 9545796..44cfeb3 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -6654,27 +6654,32 @@ func_create_testdir ()
   if test -n "$distributed_built_sources" || test -n "$tests_distributed_built_sources"; then
     (cd "$testdir"
      ./configure || func_exit 1
-       if test -n "$distributed_built_sources"; then
-         cd "$sourcebase"
-         echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
-         $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
-               built_sources \
-           || func_exit 1
-         cd ..
-       fi
-       if test -n "$tests_distributed_built_sources"; then
-         cd "$testsbase"
-         echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
-         $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
-               built_sources \
-           || func_exit 1
-         cd ..
-       fi
+     if test -n "$distributed_built_sources"; then
+       cd "$sourcebase"
+       echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
+       $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
+             built_sources \
+         || func_exit 1
+       cd ..
+     fi
+     if test -n "$tests_distributed_built_sources"; then
+       cd "$testsbase"
+       echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
+       $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
+             built_sources \
+         || func_exit 1
+       cd ..
+     fi
      $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
            distclean \
        || func_exit 1
     ) || func_exit 1
   fi
+  (cd "$testdir"
+   if test -f build-aux/test-driver; then
+     patch build-aux/test-driver < "$gnulib_dir"/build-aux/test-driver.diff || func_exit 1
+   fi
+  ) || func_exit 1
 }
 
 # func_create_megatestdir megatestdir allmodules
@@ -6775,6 +6780,9 @@ func_create_megatestdir ()
    func_execute_command ${AUTOCONF} || func_exit 1
    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
    rm -rf autom4te.cache
+   if test -f build-aux/test-driver; then
+     patch build-aux/test-driver < "$gnulib_dir"/build-aux/test-driver.diff || func_exit 1
+   fi
   ) || func_exit 1
 }
 
-- 
2.7.4


[-- Attachment #3: 0002-fchownat-Fix-compilation-error-on-Android-4.3.patch --]
[-- Type: text/x-patch, Size: 4502 bytes --]

From 239485d0b3f04fd9ba8d3bd4bb99473b00ab9078 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Thu, 24 Jan 2019 23:51:11 +0100
Subject: [PATCH 2/7] fchownat: Fix compilation error on Android 4.3.

* lib/unistd.in.h: Include <sys/stat.h> when module 'fchownat' is in
use.
* m4/fchownat.m4 (gl_FUNC_FCHOWNAT_DEREF_BUG,
gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG): Include also <sys/stat.h>.
* doc/posix-functions/fchownat.texi: Mention the issue.
---
 ChangeLog                         |  9 +++++++++
 doc/posix-functions/fchownat.texi | 20 ++++++++++++--------
 lib/unistd.in.h                   |  7 +++++++
 m4/fchownat.m4                    |  6 +++++-
 4 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7ba92a9..5606681 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-01-24  Bruno Haible  <bruno@clisp.org>
+
+	fchownat: Fix compilation error on Android 4.3.
+	* lib/unistd.in.h: Include <sys/stat.h> when module 'fchownat' is in
+	use.
+	* m4/fchownat.m4 (gl_FUNC_FCHOWNAT_DEREF_BUG,
+	gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG): Include also <sys/stat.h>.
+	* doc/posix-functions/fchownat.texi: Mention the issue.
+
 2019-01-23  Bruno Haible  <bruno@clisp.org>
 
 	gnulib-tool: Support running testdirs on Android.
diff --git a/doc/posix-functions/fchownat.texi b/doc/posix-functions/fchownat.texi
index c33bdc4..47a7225 100644
--- a/doc/posix-functions/fchownat.texi
+++ b/doc/posix-functions/fchownat.texi
@@ -9,6 +9,18 @@ Gnulib module: fchownat
 Portability problems fixed by Gnulib:
 @itemize
 @item
+This function is missing on some platforms:
+glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
+AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin 1.5.x, mingw, MSVC 14, Interix 3.5, BeOS.
+But the replacement function is not safe to be used in libraries and
+is not multithread-safe.  Also, the replacement may fail to change
+symlinks if @code{lchown} is unsupported, or fail altogether if
+@code{chown} is unsupported.
+@item
+This function is declared in @code{<sys/stat.h>}, not in @code{<unistd.h>},
+on some platforms:
+Android 4.3.
+@item
 Some platforms fail to detect trailing slash on non-directories, as in
 @code{fchown(dir,"link-to-file/",uid,gid,flag)}:
 Solaris 9.
@@ -19,14 +31,6 @@ Linux kernel 2.6.17.
 @item
 This function does not fail for an empty filename on some platforms:
 Linux with glibc < 2.11.
-@item
-This function is missing on some platforms:
-glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
-AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin 1.5.x, mingw, MSVC 14, Interix 3.5, BeOS.
-But the replacement function is not safe to be used in libraries and
-is not multithread-safe.  Also, the replacement may fail to change
-symlinks if @code{lchown} is unsupported, or fail altogether if
-@code{chown} is unsupported.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 49e5673..eb2534e 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -113,6 +113,13 @@
 # include <netdb.h>
 #endif
 
+/* Android 4.3 declares fchownat in <sys/stat.h>, not in <unistd.h>.  */
+/* But avoid namespace pollution on glibc systems.  */
+#if (@GNULIB_FCHOWNAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
+    && !defined __GLIBC__
+# include <sys/stat.h>
+#endif
+
 /* MSVC defines off_t in <sys/types.h>.
    May also define off_t to a 64-bit type on native Windows.  */
 #if !@HAVE_UNISTD_H@ || @WINDOWS_64_BIT_OFF_T@
diff --git a/m4/fchownat.m4 b/m4/fchownat.m4
index 5cca8b5..023e3cb 100644
--- a/m4/fchownat.m4
+++ b/m4/fchownat.m4
@@ -1,4 +1,4 @@
-# fchownat.m4 serial 2
+# fchownat.m4 serial 3
 dnl Copyright (C) 2004-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,
@@ -56,6 +56,8 @@ AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
           [[
 #include <fcntl.h>
 #include <unistd.h>
+/* Android 4.3 declares fchownat() in <sys/stat.h> instead.  */
+#include <sys/stat.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -86,6 +88,8 @@ AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
        [AC_LANG_PROGRAM(
           [[#include <unistd.h>
             #include <fcntl.h>
+            /* Android 4.3 declares fchownat() in <sys/stat.h> instead.  */
+            #include <sys/stat.h>
           ]],
           [[int fd;
             int ret;
-- 
2.7.4


[-- Attachment #4: 0003-renameat-Fix-compilation-error-on-Android-4.3.patch --]
[-- Type: text/x-patch, Size: 3456 bytes --]

From 881edc83d5cdf29b7697353db5e6800a6deb46d5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 25 Jan 2019 00:03:12 +0100
Subject: [PATCH 3/7] renameat: Fix compilation error on Android 4.3.

* lib/stdio.in.h: Include <sys/stat.h> when module 'renameat' is in use.
* doc/posix-functions/renameat.texi: Mention the issue.
---
 ChangeLog                         |  6 ++++++
 doc/posix-functions/renameat.texi | 25 +++++++++++++++----------
 lib/stdio.in.h                    |  7 +++++++
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5606681..fad53ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
+	renameat: Fix compilation error on Android 4.3.
+	* lib/stdio.in.h: Include <sys/stat.h> when module 'renameat' is in use.
+	* doc/posix-functions/renameat.texi: Mention the issue.
+
+2019-01-24  Bruno Haible  <bruno@clisp.org>
+
 	fchownat: Fix compilation error on Android 4.3.
 	* lib/unistd.in.h: Include <sys/stat.h> when module 'fchownat' is in
 	use.
diff --git a/doc/posix-functions/renameat.texi b/doc/posix-functions/renameat.texi
index 1411e2e..bbd1110 100644
--- a/doc/posix-functions/renameat.texi
+++ b/doc/posix-functions/renameat.texi
@@ -9,6 +9,21 @@ Gnulib module: renameat
 Portability problems fixed by Gnulib:
 @itemize
 @item
+This function is missing on some platforms:
+glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
+AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 8, Cygwin 1.5.x, mingw, MSVC 14,
+Interix 3.5, BeOS.
+But the replacement function is not safe to be used in libraries and is not
+multithread-safe.
+@item
+This function is declared in @code{<unistd.h>}, not in @code{<stdio.h>},
+on some platforms:
+NetBSD 7.0, Solaris 11.4.
+@item
+This function is declared in @code{<sys/stat.h>}, not in @code{<stdio.h>},
+on some platforms:
+Android 4.3.
+@item
 This function does not reject trailing slashes on non-directories on
 some platforms, as in @code{renameat(fd,"file",fd,"new/")}:
 Solaris 11.4.
@@ -16,16 +31,6 @@ Solaris 11.4.
 This function ignores trailing slashes on symlinks on some platforms,
 such that @code{renameat(fd,"link/",fd,"new")} corrupts @file{link}:
 Solaris 9.
-@item
-This function is declared in @code{<unistd.h>} instead of @code{<stdio.h>}
-on some platforms:
-NetBSD 7.0, Solaris 11.4.
-@item
-This function is missing on some platforms:
-glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
-AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 8, Cygwin 1.5.x, mingw, MSVC 14,
-Interix 3.5, BeOS.
-But the replacement function is not safe to be used in libraries and is not multithread-safe.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index c7acb66..98c8093 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -118,6 +118,13 @@
 # include <unistd.h>
 #endif
 
+/* Android 4.3 declares renameat in <sys/stat.h>, not in <stdio.h>.  */
+/* But in any case avoid namespace pollution on glibc systems.  */
+#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
+    && ! defined __GLIBC__
+# include <sys/stat.h>
+#endif
+
 /* MSVC declares 'perror' in <stdlib.h>, not in <stdio.h>.  We must include
    it before we  #define perror rpl_perror.  */
 /* But in any case avoid namespace pollution on glibc systems.  */
-- 
2.7.4


[-- Attachment #5: 0004-unlinkat-Fix-compilation-error-on-Android-4.3.patch --]
[-- Type: text/x-patch, Size: 2780 bytes --]

From 3842cd1d67868fdd3a5aeeaa37e6a8f0d7818c3f Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 25 Jan 2019 00:08:52 +0100
Subject: [PATCH 4/7] unlinkat: Fix compilation error on Android 4.3.

* lib/unistd.in.h: Include <fcntl.h> when module 'unlinkat' is in use
also on Android.
* doc/posix-functions/unlinkat.texi: Mention the issue.
---
 ChangeLog                         | 7 +++++++
 doc/posix-functions/unlinkat.texi | 8 ++++----
 lib/unistd.in.h                   | 6 ++++--
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fad53ae..baa8590 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
+	unlinkat: Fix compilation error on Android 4.3.
+	* lib/unistd.in.h: Include <fcntl.h> when module 'unlinkat' is in use
+	also on Android.
+	* doc/posix-functions/unlinkat.texi: Mention the issue.
+
+2019-01-24  Bruno Haible  <bruno@clisp.org>
+
 	renameat: Fix compilation error on Android 4.3.
 	* lib/stdio.in.h: Include <sys/stat.h> when module 'renameat' is in use.
 	* doc/posix-functions/renameat.texi: Mention the issue.
diff --git a/doc/posix-functions/unlinkat.texi b/doc/posix-functions/unlinkat.texi
index de9d517..fb4e69f 100644
--- a/doc/posix-functions/unlinkat.texi
+++ b/doc/posix-functions/unlinkat.texi
@@ -14,15 +14,15 @@ glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
 AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin 1.5.x, mingw, MSVC 14, Interix 3.5, BeOS.
 But the replacement function is not safe to be used in libraries and is not multithread-safe.
 @item
+This function is declared in @code{<fcntl.h>}, not in @code{<unistd.h>},
+on some platforms:
+Cygwin 1.7.1, Android 4.3.
+@item
 On Mac OS X 10.10, in a writable HFS mount, @code{unlinkat(fd, "..", 0)} succeeds
 without doing anything.
 @item
 Some systems mistakenly succeed on @code{unlinkat(fd,"file/",flag)}:
 GNU/Hurd, Solaris 9.
-@item
-Some platforms declare this function in @code{fcntl.h} instead of
-@code{unistd.h}:
-Cygwin 1.7.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index eb2534e..0ff7396 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -68,9 +68,11 @@
 # include <stdio.h>
 #endif
 
-/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>.  */
+/* Cygwin 1.7.1 and Android 4.3 declare unlinkat in <fcntl.h>, not in
+   <unistd.h>.  */
 /* But avoid namespace pollution on glibc systems.  */
-#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \
+#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) \
+    && (defined __CYGWIN__ || defined __ANDROID__) \
     && ! defined __GLIBC__
 # include <fcntl.h>
 #endif
-- 
2.7.4


[-- Attachment #6: 0005-fdatasync-Fix-compilation-error-on-Android-4.3.patch --]
[-- Type: text/x-patch, Size: 2687 bytes --]

From d591eab8486390c258151b0e3ec94285c75a86d8 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 25 Jan 2019 00:15:50 +0100
Subject: [PATCH 5/7] fdatasync: Fix compilation error on Android 4.3.

* m4/fdatasync.m4 (gl_FUNC_FDATASYNC): On platforms other than Solaris,
test whether fdatasync() exists.
---
 ChangeLog       |  6 ++++++
 m4/fdatasync.m4 | 28 ++++++++++++++++++++--------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index baa8590..4955af1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
+	fdatasync: Fix compilation error on Android 4.3.
+	* m4/fdatasync.m4 (gl_FUNC_FDATASYNC): On platforms other than Solaris,
+	test whether fdatasync() exists.
+
+2019-01-24  Bruno Haible  <bruno@clisp.org>
+
 	unlinkat: Fix compilation error on Android 4.3.
 	* lib/unistd.in.h: Include <fcntl.h> when module 'unlinkat' is in use
 	also on Android.
diff --git a/m4/fdatasync.m4 b/m4/fdatasync.m4
index c2ea85e..fe221cc 100644
--- a/m4/fdatasync.m4
+++ b/m4/fdatasync.m4
@@ -1,4 +1,4 @@
-# fdatasync.m4 serial 4
+# fdatasync.m4 serial 5
 dnl Copyright (C) 2008-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,
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_FDATASYNC],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   dnl Using AC_CHECK_FUNCS_ONCE would break our subsequent AC_SEARCH_LIBS
   AC_CHECK_DECLS_ONCE([fdatasync])
@@ -21,12 +22,23 @@ AC_DEFUN([gl_FUNC_FDATASYNC],
       HAVE_FDATASYNC=0
     fi
   else
-    dnl Solaris <= 2.6 has fdatasync() in libposix4.
-    dnl Solaris 7..10 has it in librt.
-    gl_saved_libs=$LIBS
-    AC_SEARCH_LIBS([fdatasync], [rt posix4],
-                   [test "$ac_cv_search_fdatasync" = "none required" ||
-                    LIB_FDATASYNC=$ac_cv_search_fdatasync])
-    LIBS=$gl_saved_libs
+    case "$host_os" in
+      solaris*)
+        dnl Solaris <= 2.6 has fdatasync() in libposix4.
+        dnl Solaris 7..10 has it in librt.
+        gl_saved_libs=$LIBS
+        AC_SEARCH_LIBS([fdatasync], [rt posix4],
+          [test "$ac_cv_search_fdatasync" = "none required" ||
+           LIB_FDATASYNC=$ac_cv_search_fdatasync])
+        LIBS=$gl_saved_libs
+        ;;
+      *)
+        dnl Android 4.3 does not have fdatasync but declares it.
+        AC_CHECK_FUNCS([fdatasync])
+        if test $ac_cv_func_fdatasync = no; then
+          HAVE_FDATASYNC=0
+        fi
+        ;;
+    esac
   fi
 ])
-- 
2.7.4


[-- Attachment #7: 0006-mbtowc-Fix-compilation-error-on-Android-4.3.patch --]
[-- Type: text/x-patch, Size: 6454 bytes --]

From 02611ab0826cb35f4c5c6c2a2198ada0d6f20296 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 25 Jan 2019 00:42:40 +0100
Subject: [PATCH 6/7] 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.
---
 ChangeLog                       | 12 ++++++++++++
 doc/posix-functions/mbtowc.texi |  6 +++---
 lib/stdlib.in.h                 |  9 +++++++++
 m4/mbtowc.m4                    | 11 ++++++++---
 m4/stdlib_h.m4                  |  5 +++--
 modules/mbtowc                  |  6 +++---
 modules/stdlib                  |  1 +
 7 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4955af1..24d5755 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 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.
 	* m4/fdatasync.m4 (gl_FUNC_FDATASYNC): On platforms other than Solaris,
 	test whether fdatasync() exists.
diff --git a/doc/posix-functions/mbtowc.texi b/doc/posix-functions/mbtowc.texi
index 022e1a2..5188a7f 100644
--- a/doc/posix-functions/mbtowc.texi
+++ b/doc/posix-functions/mbtowc.texi
@@ -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
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index d80d7ec..0f581d9 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -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@
diff --git a/m4/mbtowc.m4 b/m4/mbtowc.m4
index 202c3fb..5a4b92e 100644
--- a/m4/mbtowc.m4
+++ b/m4/mbtowc.m4
@@ -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
 ])
 
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index cf06428..c449a54 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -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])
diff --git a/modules/mbtowc b/modules/mbtowc
index a665e22..2db32de 100644
--- a/modules/mbtowc
+++ b/modules/mbtowc
@@ -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
diff --git a/modules/stdlib b/modules/stdlib
index 62224e8..dd1556e 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -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' \
-- 
2.7.4


[-- Attachment #8: 0007-random-Fix-compilation-error-on-Android-4.3.patch --]
[-- Type: text/x-patch, Size: 15426 bytes --]

From de9ed4e371d8bde6c2fd47ca9612ed150da51c10 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 25 Jan 2019 01:36:26 +0100
Subject: [PATCH 7/7] random: Fix compilation error on Android 4.3.

* lib/stdlib.in.h (random, srandom): Test also REPLACE_RANDOM.
(initstate): Test REPLACE_INITSTATE and HAVE_INITSTATE, not HAVE_RANDOM.
(setstate): Test REPLACE_SETSTATE and HAVE_SETSTATE, not HAVE_RANDOM.
* m4/random.m4 (gl_FUNC_RANDOM): Set HAVE_INITSTATE, HAVE_SETSTATE,
REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_INITSTATE,
HAVE_SETSTATE, REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
* modules/stdlib (Makefile.am): Substitute HAVE_INITSTATE, HAVE_SETSTATE,
REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
* modules/random (Depends-on, configure.ac): Test also REPLACE_RANDOM,
REPLACE_INITSTATE, REPLACE_SETSTATE.
* doc/posix-functions/random.texi: Correct the description of the
situation on Android.
* doc/posix-functions/srandom.texi: Likewise.
* doc/posix-functions/rand.texi: Likewise.
* doc/posix-functions/srand.texi: Likewise.
---
 ChangeLog                        | 20 ++++++++++++++
 doc/posix-functions/rand.texi    |  2 +-
 doc/posix-functions/random.texi  |  7 ++++-
 doc/posix-functions/srand.texi   |  2 +-
 doc/posix-functions/srandom.texi |  5 +++-
 lib/stdlib.in.h                  | 59 +++++++++++++++++++++++++++++++++-------
 m4/random.m4                     | 23 +++++++++++++++-
 m4/stdlib_h.m4                   |  7 ++++-
 modules/random                   |  8 +++---
 modules/stdlib                   |  5 ++++
 10 files changed, 118 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 24d5755..cd89cc3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
+	random: Fix compilation error on Android 4.3.
+	* lib/stdlib.in.h (random, srandom): Test also REPLACE_RANDOM.
+	(initstate): Test REPLACE_INITSTATE and HAVE_INITSTATE, not HAVE_RANDOM.
+	(setstate): Test REPLACE_SETSTATE and HAVE_SETSTATE, not HAVE_RANDOM.
+	* m4/random.m4 (gl_FUNC_RANDOM): Set HAVE_INITSTATE, HAVE_SETSTATE,
+	REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_INITSTATE,
+	HAVE_SETSTATE, REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* modules/stdlib (Makefile.am): Substitute HAVE_INITSTATE, HAVE_SETSTATE,
+	REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* modules/random (Depends-on, configure.ac): Test also REPLACE_RANDOM,
+	REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* doc/posix-functions/random.texi: Correct the description of the
+	situation on Android.
+	* doc/posix-functions/srandom.texi: Likewise.
+	* doc/posix-functions/rand.texi: Likewise.
+	* doc/posix-functions/srand.texi: Likewise.
+
+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
diff --git a/doc/posix-functions/rand.texi b/doc/posix-functions/rand.texi
index d8446ea..decf1fc 100644
--- a/doc/posix-functions/rand.texi
+++ b/doc/posix-functions/rand.texi
@@ -13,6 +13,6 @@ Portability problems fixed by Gnulib:
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
+This function is only defined as an inline function on some platforms:
 Android 4.4.
 @end itemize
diff --git a/doc/posix-functions/random.texi b/doc/posix-functions/random.texi
index 9280102..36b5857 100644
--- a/doc/posix-functions/random.texi
+++ b/doc/posix-functions/random.texi
@@ -10,7 +10,12 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-Solaris 2.4, mingw, MSVC 14, Android 4.4.
+Solaris 2.4, mingw, MSVC 14.
+@item
+This function is only defined as an inline function on some platforms:
+Android 4.4.
+@item
+
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/doc/posix-functions/srand.texi b/doc/posix-functions/srand.texi
index 344f631..5a6e6b7 100644
--- a/doc/posix-functions/srand.texi
+++ b/doc/posix-functions/srand.texi
@@ -13,6 +13,6 @@ Portability problems fixed by Gnulib:
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
+This function is only defined as an inline function on some platforms:
 Android 4.4.
 @end itemize
diff --git a/doc/posix-functions/srandom.texi b/doc/posix-functions/srandom.texi
index 7c3292a..09d033e 100644
--- a/doc/posix-functions/srandom.texi
+++ b/doc/posix-functions/srandom.texi
@@ -10,7 +10,10 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-Solaris 2.4, mingw, MSVC 14, Android 4.4.
+Solaris 2.4, mingw, MSVC 14.
+@item
+This function is only defined as an inline function on some platforms:
+Android 4.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 0f581d9..be8ab3b 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -582,10 +582,19 @@ _GL_WARN_ON_USE (qsort_r, "qsort_r is not portable - "
 
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@
+# if @REPLACE_RANDOM@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef random
+#   define random rpl_random
+#  endif
+_GL_FUNCDECL_RPL (random, long, (void));
+_GL_CXXALIAS_RPL (random, long, (void));
+# else
+#  if !@HAVE_RANDOM@
 _GL_FUNCDECL_SYS (random, long, (void));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (random, long, (void));
+# endif
 _GL_CXXALIASWARN (random);
 #elif defined GNULIB_POSIXCHECK
 # undef random
@@ -596,10 +605,19 @@ _GL_WARN_ON_USE (random, "random is unportable - "
 #endif
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@
+# if @REPLACE_RANDOM@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef srandom
+#   define srandom rpl_srandom
+#  endif
+_GL_FUNCDECL_RPL (srandom, void, (unsigned int seed));
+_GL_CXXALIAS_RPL (srandom, void, (unsigned int seed));
+# else
+#  if !@HAVE_RANDOM@
 _GL_FUNCDECL_SYS (srandom, void, (unsigned int seed));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (srandom, void, (unsigned int seed));
+# endif
 _GL_CXXALIASWARN (srandom);
 #elif defined GNULIB_POSIXCHECK
 # undef srandom
@@ -610,31 +628,52 @@ _GL_WARN_ON_USE (srandom, "srandom is unportable - "
 #endif
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@ || !@HAVE_DECL_INITSTATE@
+# if @REPLACE_INITSTATE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef initstate
+#   define initstate rpl_initstate
+#  endif
+_GL_FUNCDECL_RPL (initstate, char *,
+                  (unsigned int seed, char *buf, size_t buf_size)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (initstate, char *,
+                  (unsigned int seed, char *buf, size_t buf_size));
+# else
+#  if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
 _GL_FUNCDECL_SYS (initstate, char *,
                   (unsigned int seed, char *buf, size_t buf_size)
                   _GL_ARG_NONNULL ((2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (initstate, char *,
                   (unsigned int seed, char *buf, size_t buf_size));
+# endif
 _GL_CXXALIASWARN (initstate);
 #elif defined GNULIB_POSIXCHECK
 # undef initstate
-# if HAVE_RAW_DECL_INITSTATE_R
+# if HAVE_RAW_DECL_INITSTATE
 _GL_WARN_ON_USE (initstate, "initstate is unportable - "
                  "use gnulib module random for portability");
 # endif
 #endif
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@ || !@HAVE_DECL_SETSTATE@
+# if @REPLACE_SETSTATE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef setstate
+#   define setstate rpl_setstate
+#  endif
+_GL_FUNCDECL_RPL (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (setstate, char *, (char *arg_state));
+# else
+#  if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
 _GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (setstate, char *, (char *arg_state));
+# endif
 _GL_CXXALIASWARN (setstate);
 #elif defined GNULIB_POSIXCHECK
 # undef setstate
-# if HAVE_RAW_DECL_SETSTATE_R
+# if HAVE_RAW_DECL_SETSTATE
 _GL_WARN_ON_USE (setstate, "setstate is unportable - "
                  "use gnulib module random for portability");
 # endif
diff --git a/m4/random.m4 b/m4/random.m4
index 996c406..15da67e 100644
--- a/m4/random.m4
+++ b/m4/random.m4
@@ -1,4 +1,4 @@
-# random.m4 serial 3
+# random.m4 serial 4
 dnl Copyright (C) 2012-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,
@@ -21,6 +21,27 @@ AC_DEFUN([gl_FUNC_RANDOM],
     ])
   if test $gl_cv_func_random = no; then
     HAVE_RANDOM=0
+    HAVE_INITSTATE=0
+    HAVE_SETSTATE=0
+  else
+    AC_CHECK_FUNCS([initstate setstate])
+    if test $ac_cv_func_initstate = no; then
+      HAVE_INITSTATE=0
+    fi
+    if test $ac_cv_func_setstate = no; then
+      HAVE_SETSTATE=0
+    fi
+    if test $ac_cv_func_initstate = no || test $ac_cv_func_setstate = no; then
+      dnl In order to define initstate or setstate, we need to define all the
+      dnl functions at once.
+      REPLACE_RANDOM=1
+      if test $ac_cv_func_initstate = yes; then
+        REPLACE_INITSTATE=1
+      fi
+      if test $ac_cv_func_setstate = yes; then
+        REPLACE_SETSTATE=1
+      fi
+    fi
   fi
 
   AC_CHECK_DECLS_ONCE([initstate])
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index c449a54..c5db804 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 46
+# stdlib_h.m4 serial 47
 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,
@@ -81,6 +81,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   HAVE_DECL_GETLOADAVG=1;    AC_SUBST([HAVE_DECL_GETLOADAVG])
   HAVE_GETSUBOPT=1;          AC_SUBST([HAVE_GETSUBOPT])
   HAVE_GRANTPT=1;            AC_SUBST([HAVE_GRANTPT])
+  HAVE_INITSTATE=1;          AC_SUBST([HAVE_INITSTATE])
   HAVE_DECL_INITSTATE=1;     AC_SUBST([HAVE_DECL_INITSTATE])
   HAVE_MBTOWC=1;             AC_SUBST([HAVE_MBTOWC])
   HAVE_MKDTEMP=1;            AC_SUBST([HAVE_MKDTEMP])
@@ -101,6 +102,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   HAVE_SECURE_GETENV=1;      AC_SUBST([HAVE_SECURE_GETENV])
   HAVE_SETENV=1;             AC_SUBST([HAVE_SETENV])
   HAVE_DECL_SETENV=1;        AC_SUBST([HAVE_DECL_SETENV])
+  HAVE_SETSTATE=1;           AC_SUBST([HAVE_SETSTATE])
   HAVE_DECL_SETSTATE=1;      AC_SUBST([HAVE_DECL_SETSTATE])
   HAVE_STRTOD=1;             AC_SUBST([HAVE_STRTOD])
   HAVE_STRTOLL=1;            AC_SUBST([HAVE_STRTOLL])
@@ -111,6 +113,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   HAVE_DECL_UNSETENV=1;      AC_SUBST([HAVE_DECL_UNSETENV])
   REPLACE_CALLOC=0;          AC_SUBST([REPLACE_CALLOC])
   REPLACE_CANONICALIZE_FILE_NAME=0;  AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
+  REPLACE_INITSTATE=0;       AC_SUBST([REPLACE_INITSTATE])
   REPLACE_MALLOC=0;          AC_SUBST([REPLACE_MALLOC])
   REPLACE_MBTOWC=0;          AC_SUBST([REPLACE_MBTOWC])
   REPLACE_MKSTEMP=0;         AC_SUBST([REPLACE_MKSTEMP])
@@ -118,10 +121,12 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   REPLACE_PTSNAME_R=0;       AC_SUBST([REPLACE_PTSNAME_R])
   REPLACE_PUTENV=0;          AC_SUBST([REPLACE_PUTENV])
   REPLACE_QSORT_R=0;         AC_SUBST([REPLACE_QSORT_R])
+  REPLACE_RANDOM=0;          AC_SUBST([REPLACE_RANDOM])
   REPLACE_RANDOM_R=0;        AC_SUBST([REPLACE_RANDOM_R])
   REPLACE_REALLOC=0;         AC_SUBST([REPLACE_REALLOC])
   REPLACE_REALPATH=0;        AC_SUBST([REPLACE_REALPATH])
   REPLACE_SETENV=0;          AC_SUBST([REPLACE_SETENV])
+  REPLACE_SETSTATE=0;        AC_SUBST([REPLACE_SETSTATE])
   REPLACE_STRTOD=0;          AC_SUBST([REPLACE_STRTOD])
   REPLACE_UNSETENV=0;        AC_SUBST([REPLACE_UNSETENV])
   REPLACE_WCTOMB=0;          AC_SUBST([REPLACE_WCTOMB])
diff --git a/modules/random b/modules/random
index 706096b..e58ebd1 100644
--- a/modules/random
+++ b/modules/random
@@ -6,14 +6,14 @@ lib/random.c
 m4/random.m4
 
 Depends-on:
-libc-config     [test $HAVE_RANDOM = 0]
+libc-config     [test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1]
 stdlib
-stdint          [test $HAVE_RANDOM = 0]
-random_r        [test $HAVE_RANDOM = 0]
+stdint          [test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1]
+random_r        [test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1]
 
 configure.ac:
 gl_FUNC_RANDOM
-if test $HAVE_RANDOM = 0; then
+if test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1; then
   AC_LIBOBJ([random])
   gl_PREREQ_RANDOM
 fi
diff --git a/modules/stdlib b/modules/stdlib
index dd1556e..a43f79c 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -72,6 +72,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
 	      -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
 	      -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
 	      -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
+	      -e 's|@''HAVE_INITSTATE''@|$(HAVE_INITSTATE)|g' \
 	      -e 's|@''HAVE_DECL_INITSTATE''@|$(HAVE_DECL_INITSTATE)|g' \
 	      -e 's|@''HAVE_MBTOWC''@|$(HAVE_MBTOWC)|g' \
 	      -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
@@ -91,6 +92,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
 	      -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
 	      -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \
 	      -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \
+	      -e 's|@''HAVE_SETSTATE''@|$(HAVE_SETSTATE)|g' \
 	      -e 's|@''HAVE_DECL_SETSTATE''@|$(HAVE_DECL_SETSTATE)|g' \
 	      -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
 	      -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
@@ -101,6 +103,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
 	      -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
 	      -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
 	      -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
+	      -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
 	      -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
 	      -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
 	      -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
@@ -108,10 +111,12 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
 	      -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
 	      -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
 	      -e 's|@''REPLACE_QSORT_R''@|$(REPLACE_QSORT_R)|g' \
+	      -e 's|@''REPLACE_RANDOM''@|$(REPLACE_RANDOM)|g' \
 	      -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
 	      -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
 	      -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
 	      -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
+	      -e 's|@''REPLACE_SETSTATE''@|$(REPLACE_SETSTATE)|g' \
 	      -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
 	      -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
 	      -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-25  1:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25  1:14 fix some build errors on Android 4.3 Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).