Building a gnulib testdir on Android (with the Termux development environment)
I see these errors:

../gllib/stdio.h:1461:19: error: no member named 'getw' in the global 
namespace; did you mean 'getc'?
_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../gllib/stdio.h:1700:19: error: no member named 'putw' in the global namespace
_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These two patches fix them.


2023-01-03  Bruno Haible  <br...@clisp.org>

        stdio: Fix error in C++ mode on Android, due to putw.
        * lib/stdio.in.h (putw): Don't declare in the C++ namespace if putw is
        not declared.
        * m4/stdio_h.m4 (gl_STDIO_H): Test whether putw is declared.
        (gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_PUTW.
        * modules/stdio (Makefile.am): Substitute HAVE_DECL_PUTW.
        * doc/glibc-functions/putw.texi: Update regarding Android.

2023-01-03  Bruno Haible  <br...@clisp.org>

        stdio: Fix error in C++ mode on Android, due to getw.
        * lib/stdio.in.h (getw): Don't declare in the C++ namespace if getw is
        not declared.
        * m4/stdio_h.m4 (gl_STDIO_H): Test whether getw is declared.
        (gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_GETW.
        * modules/stdio (Makefile.am): Substitute HAVE_DECL_GETW.

>From 4110d771302b739c26b247e8ebff2ca7a89a4827 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 3 Jan 2023 17:11:19 +0100
Subject: [PATCH 1/2] stdio: Fix error in C++ mode on Android, due to getw.

* lib/stdio.in.h (getw): Don't declare in the C++ namespace if getw is
not declared.
* m4/stdio_h.m4 (gl_STDIO_H): Test whether getw is declared.
(gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_GETW.
* modules/stdio (Makefile.am): Substitute HAVE_DECL_GETW.
---
 ChangeLog      | 9 +++++++++
 lib/stdio.in.h | 4 ++++
 m4/stdio_h.m4  | 8 +++++++-
 modules/stdio  | 1 +
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index c95e8f5586..e73c76550f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-01-03  Bruno Haible  <br...@clisp.org>
+
+	stdio: Fix error in C++ mode on Android, due to getw.
+	* lib/stdio.in.h (getw): Don't declare in the C++ namespace if getw is
+	not declared.
+	* m4/stdio_h.m4 (gl_STDIO_H): Test whether getw is declared.
+	(gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_GETW.
+	* modules/stdio (Makefile.am): Substitute HAVE_DECL_GETW.
+
 2023-01-02  Bruno Haible  <br...@clisp.org>
 
 	sigsegv: Fix compilation error on Android 4.3.
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 59cbea3d47..462762fe45 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -951,9 +951,13 @@ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
 #  endif
 _GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream));
 # else
+#  if @HAVE_DECL_GETW@
 _GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
+#  endif
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (getw);
+# endif
 #endif
 
 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index 94271e11e7..421f594cfe 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 59
+# stdio_h.m4 serial 60
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -82,6 +82,11 @@ AC_DEFUN_ONCE([gl_STDIO_H],
   if test $ac_cv_have_decl_fcloseall = no; then
     HAVE_DECL_FCLOSEALL=0
   fi
+
+  AC_CHECK_DECLS_ONCE([getw])
+  if test $ac_cv_have_decl_getw = no; then
+    HAVE_DECL_GETW=0
+  fi
 ])
 
 # gl_STDIO_MODULE_INDICATOR([modulename])
@@ -178,6 +183,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DECL_FTELLO=1;            AC_SUBST([HAVE_DECL_FTELLO])
   HAVE_DECL_GETDELIM=1;          AC_SUBST([HAVE_DECL_GETDELIM])
   HAVE_DECL_GETLINE=1;           AC_SUBST([HAVE_DECL_GETLINE])
+  HAVE_DECL_GETW=1;              AC_SUBST([HAVE_DECL_GETW])
   HAVE_DECL_OBSTACK_PRINTF=1;    AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
   HAVE_DECL_SNPRINTF=1;          AC_SUBST([HAVE_DECL_SNPRINTF])
   HAVE_DECL_VSNPRINTF=1;         AC_SUBST([HAVE_DECL_VSNPRINTF])
diff --git a/modules/stdio b/modules/stdio
index ff3a8d55af..6504a01372 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -130,6 +130,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
 	      -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \
 	      -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
 	      -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
+	      -e 's|@''HAVE_DECL_GETW''@|$(HAVE_DECL_GETW)|g' \
 	      -e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \
 	      -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
 	      -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
-- 
2.34.1

>From fef91f09672dc691664dca0c559842ab35a5796b Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 3 Jan 2023 17:14:33 +0100
Subject: [PATCH 2/2] stdio: Fix error in C++ mode on Android, due to putw.

* lib/stdio.in.h (putw): Don't declare in the C++ namespace if putw is
not declared.
* m4/stdio_h.m4 (gl_STDIO_H): Test whether putw is declared.
(gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_PUTW.
* modules/stdio (Makefile.am): Substitute HAVE_DECL_PUTW.
* doc/glibc-functions/putw.texi: Update regarding Android.
---
 ChangeLog                     | 10 ++++++++++
 doc/glibc-functions/putw.texi |  3 +++
 lib/stdio.in.h                |  4 ++++
 m4/stdio_h.m4                 |  8 +++++++-
 modules/stdio                 |  1 +
 5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e73c76550f..88d5faa592 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-01-03  Bruno Haible  <br...@clisp.org>
+
+	stdio: Fix error in C++ mode on Android, due to putw.
+	* lib/stdio.in.h (putw): Don't declare in the C++ namespace if putw is
+	not declared.
+	* m4/stdio_h.m4 (gl_STDIO_H): Test whether putw is declared.
+	(gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_PUTW.
+	* modules/stdio (Makefile.am): Substitute HAVE_DECL_PUTW.
+	* doc/glibc-functions/putw.texi: Update regarding Android.
+
 2023-01-03  Bruno Haible  <br...@clisp.org>
 
 	stdio: Fix error in C++ mode on Android, due to getw.
diff --git a/doc/glibc-functions/putw.texi b/doc/glibc-functions/putw.texi
index 8591c43900..18383e321f 100644
--- a/doc/glibc-functions/putw.texi
+++ b/doc/glibc-functions/putw.texi
@@ -23,4 +23,7 @@ Portability problems fixed by Gnulib:
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+This function is not declared on some platforms:
+Android 9.0.
 @end itemize
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 462762fe45..8b5ef4bd2d 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -1194,9 +1194,13 @@ _GL_CXXALIASWARN (puts);
 #  endif
 _GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream));
 # else
+#  if @HAVE_DECL_PUTW@
 _GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
+#  endif
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (putw);
+# endif
 #endif
 
 #if @GNULIB_REMOVE@
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index 421f594cfe..07569961f8 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 60
+# stdio_h.m4 serial 61
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -87,6 +87,11 @@ AC_DEFUN_ONCE([gl_STDIO_H],
   if test $ac_cv_have_decl_getw = no; then
     HAVE_DECL_GETW=0
   fi
+
+  AC_CHECK_DECLS_ONCE([putw])
+  if test $ac_cv_have_decl_putw = no; then
+    HAVE_DECL_PUTW=0
+  fi
 ])
 
 # gl_STDIO_MODULE_INDICATOR([modulename])
@@ -185,6 +190,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DECL_GETLINE=1;           AC_SUBST([HAVE_DECL_GETLINE])
   HAVE_DECL_GETW=1;              AC_SUBST([HAVE_DECL_GETW])
   HAVE_DECL_OBSTACK_PRINTF=1;    AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
+  HAVE_DECL_PUTW=1;              AC_SUBST([HAVE_DECL_PUTW])
   HAVE_DECL_SNPRINTF=1;          AC_SUBST([HAVE_DECL_SNPRINTF])
   HAVE_DECL_VSNPRINTF=1;         AC_SUBST([HAVE_DECL_VSNPRINTF])
   HAVE_DPRINTF=1;                AC_SUBST([HAVE_DPRINTF])
diff --git a/modules/stdio b/modules/stdio
index 6504a01372..b8662ef0a9 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -132,6 +132,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
 	      -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
 	      -e 's|@''HAVE_DECL_GETW''@|$(HAVE_DECL_GETW)|g' \
 	      -e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \
+	      -e 's|@''HAVE_DECL_PUTW''@|$(HAVE_DECL_PUTW)|g' \
 	      -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
 	      -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
 	      -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
-- 
2.34.1

Reply via email to