Hi Po,

Po Lu <[email protected]> writes:

> `cgroup2_mount' in the nproc module expects `setmntent' to be present
> whenever mntent.h is available, but the header itself does not define
> `setmntent' on releases predating SDK 21, yielding such an error when
> compiling Emacs:
>
> nproc.c:391:15: error: implicit declaration of function 'setmntent' is 
> invalid in C99 [-Werror,-Wimplicit-function-declaration]
>   if (! (fp = setmntent ("/proc/mounts", "r")))
>               ^

Interesting. I cannot reproduce with:

    $ gnulib-tool --create-testdir --dir testdir1 nproc
    $ cd testdir1
    $ ./configure CC='cc -target aarch64-unknown-linux-android16'

Can you check if the attached patch fixes it for you?

Collin

>From c5522e4a8fd6fa5455e62f7b900c26e830bd1d53 Mon Sep 17 00:00:00 2001
Message-ID: <c5522e4a8fd6fa5455e62f7b900c26e830bd1d53.1762315082.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Tue, 4 Nov 2025 19:56:18 -0800
Subject: [PATCH] =?UTF-8?q?nproc:=20Fix=20compilation=20error=20with=20And?=
 =?UTF-8?q?roid=20API=20=E2=89=A4=2016.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reported by Po Lu in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-11/msg00027.html>.

* lib/nproc.c (cgroup2_mount): Don't assume we have setmntent if we have
mntent.h.
* m4/nproc.m4 (gl_PREREQ_NPROC): Check if setmntent is supported by the
current Android API.
---
 ChangeLog   | 10 ++++++++++
 lib/nproc.c |  4 ++--
 m4/nproc.m4 |  6 +++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 940ebffb52..8110a75fb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-11-04  Collin Funk  <[email protected]>
+
+	nproc: Fix compilation error with Android API ≤ 16.
+	Reported by Po Lu in
+	<https://lists.gnu.org/archive/html/bug-gnulib/2025-11/msg00027.html>.
+	* lib/nproc.c (cgroup2_mount): Don't assume we have setmntent if we have
+	mntent.h.
+	* m4/nproc.m4 (gl_PREREQ_NPROC): Check if setmntent is supported by the
+	current Android API.
+
 2025-11-04  Paul Eggert  <[email protected]>
 
 	time_rz: tzfree now preserves errno
diff --git a/lib/nproc.c b/lib/nproc.c
index e899ff1762..9404be1d38 100644
--- a/lib/nproc.c
+++ b/lib/nproc.c
@@ -22,7 +22,7 @@
 
 #include <errno.h>
 #include <limits.h>
-#if HAVE_MNTENT_H
+#if HAVE_SETMNTENT
 # include <mntent.h>
 #endif
 #include <stdlib.h>
@@ -385,7 +385,7 @@ cgroup2_mount (void)
   if (access ("/sys/fs/cgroup/cgroup.controllers", F_OK) == 0)
     return strdup ("/sys/fs/cgroup");
 
-#if HAVE_MNTENT_H
+#if HAVE_SETMNTENT
   /* Otherwise look for the mount point.  */
   struct mntent *mnt;
   if (! (fp = setmntent ("/proc/mounts", "r")))
diff --git a/m4/nproc.m4 b/m4/nproc.m4
index 9225779585..e9fba1533c 100644
--- a/m4/nproc.m4
+++ b/m4/nproc.m4
@@ -1,5 +1,5 @@
 # nproc.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2009-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -19,6 +19,10 @@ AC_DEFUN([gl_PREREQ_NPROC]
 
   AC_CHECK_HEADERS([mntent.h sys/pstat.h sys/param.h],,,
     [AC_INCLUDES_DEFAULT])
+  gl_CHECK_FUNCS_ANDROID([setmntent],
+    [[#include <stdio.h>
+      #include <mntent.h>
+    ]])
   dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0.
   AC_CHECK_HEADERS([sys/sysctl.h],,,
     [AC_INCLUDES_DEFAULT
-- 
2.51.1

Reply via email to