Po Lu wrote: > During the automated build of the Android port, the following errors > were encountered with the Android NDK r10b and __ANDROID_API__ set to 8 > (which is the oldest configuration Emacs supports.)... > > In file included from boot-time.c:54:0: > boot-time-aux.h: In function 'get_linux_uptime': > boot-time-aux.h:70:3: error: implicit declaration of function 'sysinfo' > [-Werror=implicit-function-declaration] > if (sysinfo (&info) >= 0) > ^
Should be fixed by the patch below. Paul Eggert wrote: > Gnulib should bypass sysinfo unless it's available. Yes. Note that it's available in Android libc already at API level 3. It's only the declaration that was added in API level 9. Also, if we write '#if HAVE_DECL_SYSINFO' instead of '9 <= __ANDROID_API__', the change might be helpful also with other Linux-based libcs that may be developed in the future. 2023-08-13 Bruno Haible <br...@clisp.org> readutmp, boot-time: Fix compilation error on Android API 8. Reported by Po Lu in <https://lists.gnu.org/archive/html/bug-gnulib/2023-08/msg00108.html>. * m4/readutmp.m4 (gl_PREREQ_READUTMP_H): Test whether sysinfo is declared. * lib/boot-time-aux.h (get_linux_uptime): Invoke sysinfo only if it is declared. * doc/glibc-functions/sysinfo.texi: Mention the Android problem. diff --git a/doc/glibc-functions/sysinfo.texi b/doc/glibc-functions/sysinfo.texi index 3b1ade31a6..16e12b12ac 100644 --- a/doc/glibc-functions/sysinfo.texi +++ b/doc/glibc-functions/sysinfo.texi @@ -17,4 +17,7 @@ @item This function is missing on some platforms: macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 5.1, Cygwin 1.7.9, mingw, MSVC 14. +@item +This function is not declared and thus not part of the Android API +for Android API levels < 9. @end itemize diff --git a/lib/boot-time-aux.h b/lib/boot-time-aux.h index 348611fc85..e59a0fd03c 100644 --- a/lib/boot-time-aux.h +++ b/lib/boot-time-aux.h @@ -65,6 +65,7 @@ get_linux_uptime (struct timespec *p_uptime) } # endif +# if HAVE_DECL_SYSINFO /* not available in Android API < 9 */ /* The sysinfo call returns the uptime with a resolution of 1 sec only. */ struct sysinfo info; if (sysinfo (&info) >= 0) @@ -73,6 +74,7 @@ get_linux_uptime (struct timespec *p_uptime) p_uptime->tv_nsec = 0; return 0; } +# endif return -1; } diff --git a/m4/readutmp.m4 b/m4/readutmp.m4 index 9dffe981b8..0a47f4bb77 100644 --- a/m4/readutmp.m4 +++ b/m4/readutmp.m4 @@ -1,4 +1,4 @@ -# readutmp.m4 serial 29 +# readutmp.m4 serial 30 dnl Copyright (C) 2002-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, @@ -103,6 +103,10 @@ AC_DEFUN_ONCE([gl_PREREQ_READUTMP_H] AC_CHECK_MEMBERS([struct utmp.ut_exit.e_termination],,,[$utmp_includes]) fi + AC_CHECK_DECLS([sysinfo],,,[[ + #include <sys/sysinfo.h> + ]]) + AC_CHECK_HEADERS_ONCE([sys/param.h]) dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0. AC_CHECK_HEADERS([sys/sysctl.h],,,