From 1bd24cc326f0abd554d5707c1cd51cdcec8fffaf Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 13 Aug 2023 16:08:33 +0200 Subject: [PATCH] readutmp, boot-time: Fix compilation error on Android API 8. Reported by Po Lu in . * 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. --- ChangeLog | 11 +++++++++++ doc/glibc-functions/sysinfo.texi | 3 +++ lib/boot-time-aux.h | 2 ++ m4/readutmp.m4 | 6 +++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9b4f07a2b1..3b651bb4b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2023-08-13 Bruno Haible + + readutmp, boot-time: Fix compilation error on Android API 8. + Reported by Po Lu in + . + * 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. + 2023-08-13 Bruno Haible readutmp, boot-time: Fix compilation error on old Android. 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 @@ Portability problems not fixed by Gnulib: @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_INCLUDES_DEFAULT AC_CHECK_MEMBERS([struct utmp.ut_exit.e_termination],,,[$utmp_includes]) fi + AC_CHECK_DECLS([sysinfo],,,[[ + #include + ]]) + AC_CHECK_HEADERS_ONCE([sys/param.h]) dnl requires on OpenBSD 4.0. AC_CHECK_HEADERS([sys/sysctl.h],,, -- 2.39.5