]> Savannah Git Hosting - gnulib.git/commitdiff
hasmntopt: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 19 Aug 2024 14:20:08 +0000 (16:20 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 19 Aug 2024 15:15:28 +0000 (17:15 +0200)
* lib/mntent.in.h: Add config.h check.
(hasmntopt): New declaration.
* lib/hasmntopt.c: New file, based on glibc/misc/mntent_r.c.
* m4/hasmntopt.m4: New file.
* m4/mntent_h.m4 (gl_MNTENT_H): Test whether hasmntopt is declared.
(gl_MNTENT_H_REQUIRE_DEFAULTS): Initialize GNULIB_HASMNTOPT.
(gl_MNTENT_H_DEFAULTS): Initialize HAVE_HASMNTOPT, HAVE_SETMNTENT,
REPLACE_HASMNTOPT.
* modules/mntent (Depends-on): Add snippet/arg-nonnull, snippet/c++defs,
snippet/warn-on-use.
(Makefile.am): Insert c++defs.h, arg-nonnull.h, warn-on-use.h into
mntent.h. Substitute GNULIB_HASMNTOPT, HAVE_HASMNTOPT, HAVE_SETMNTENT,
REPLACE_HASMNTOPT.
* modules/hasmntopt: New file.
* doc/glibc-functions/hasmntopt.texi: Mention the new module and the
musl bug.
* doc/glibc-functions/setmntent.texi: Update info about Android.
* doc/glibc-functions/getmntent_r.texi: Likewise.
* doc/glibc-functions/endmntent.texi: Likewise.

ChangeLog
doc/glibc-functions/endmntent.texi
doc/glibc-functions/getmntent_r.texi
doc/glibc-functions/hasmntopt.texi
doc/glibc-functions/setmntent.texi
lib/hasmntopt.c [new file with mode: 0644]
lib/mntent.in.h
m4/hasmntopt.m4 [new file with mode: 0644]
m4/mntent_h.m4
modules/hasmntopt [new file with mode: 0644]
modules/mntent

index 390733f163c71040ea05103521885d950c51565f..8cbd4b8a805680d14892f6ef383693b60cac28f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2024-08-19  Bruno Haible  <bruno@clisp.org>
+
+       hasmntopt: New module.
+       * lib/mntent.in.h: Add config.h check.
+       (hasmntopt): New declaration.
+       * lib/hasmntopt.c: New file, based on glibc/misc/mntent_r.c.
+       * m4/hasmntopt.m4: New file.
+       * m4/mntent_h.m4 (gl_MNTENT_H): Test whether hasmntopt is declared.
+       (gl_MNTENT_H_REQUIRE_DEFAULTS): Initialize GNULIB_HASMNTOPT.
+       (gl_MNTENT_H_DEFAULTS): Initialize HAVE_HASMNTOPT, HAVE_SETMNTENT,
+       REPLACE_HASMNTOPT.
+       * modules/mntent (Depends-on): Add snippet/arg-nonnull, snippet/c++defs,
+       snippet/warn-on-use.
+       (Makefile.am): Insert c++defs.h, arg-nonnull.h, warn-on-use.h into
+       mntent.h. Substitute GNULIB_HASMNTOPT, HAVE_HASMNTOPT, HAVE_SETMNTENT,
+       REPLACE_HASMNTOPT.
+       * modules/hasmntopt: New file.
+       * doc/glibc-functions/hasmntopt.texi: Mention the new module and the
+       musl bug.
+       * doc/glibc-functions/setmntent.texi: Update info about Android.
+       * doc/glibc-functions/getmntent_r.texi: Likewise.
+       * doc/glibc-functions/endmntent.texi: Likewise.
+
 2024-08-19  Bruno Haible  <bruno@clisp.org>
 
        mntent: New module.
index 501083ca9bc3dfdbd591c8861220bd29cdb1e439..b887e0ee6797d2692e1421f8f4ff3a44d406299d 100644 (file)
@@ -25,5 +25,5 @@ Portability problems not fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, Solaris 11.4, mingw, MSVC 14, Android 4.4.
+macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, Solaris 11.4, mingw, MSVC 14, Android API level 20.
 @end itemize
index bbd2ee97f492d83453fb6813807bf72e89e03ea0..12629a13a8737e308fa51249cb04b101887343bc 100644 (file)
@@ -25,5 +25,5 @@ Portability problems not fixed by Gnulib:
 @itemize
 @item
 This function is missing on many non-glibc platforms:
-macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.4, Cygwin 1.7.x, mingw, MSVC 14, Android 4.4.
+macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.4, Cygwin 1.7.x, mingw, MSVC 14, Android API level 20.
 @end itemize
index a4784c6eb626ffda176f5b290b76e3716c80b783..ebc92fe6c82b70e9d5191234c5af7b0c09ca95b2 100644 (file)
@@ -15,15 +15,22 @@ Documentation:
 @uref{https://www.kernel.org/doc/man-pages/online/pages/man3/hasmntopt.3.html,,man hasmntopt}.
 @end itemize
 
-Gnulib module: ---
+Gnulib module: hasmntopt
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Cygwin 3.5.3, Android API level 25.
+@item
+This function returns wrong results on some platforms:
+@c https://www.openwall.com/lists/musl/2024/08/19/1
+musl libc 1.2.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, Cygwin 2.9, mingw, MSVC 14, Android 7.1.
+macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, mingw, MSVC 14.
 @end itemize
index 291b71492cc597d9464473c72e66cf516a5bca06..930c432e8fee2de563c6f861a2b461fa85743132 100644 (file)
@@ -25,5 +25,5 @@ Portability problems not fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, Solaris 11.4, mingw, MSVC 14, Android 4.4.
+macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.1.8, Solaris 11.4, mingw, MSVC 14, Android API level 20.
 @end itemize
diff --git a/lib/hasmntopt.c b/lib/hasmntopt.c
new file mode 100644 (file)
index 0000000..15c7e82
--- /dev/null
@@ -0,0 +1,44 @@
+/* hasmntopt() function: test for the presence of a mount option.
+
+   Copyright (C) 1995-2024 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <mntent.h>
+
+#include <string.h>
+
+char *
+hasmntopt (const struct mntent *mnt, const char *opt)
+{
+  const size_t optlen = strlen (opt);
+  char *rest = mnt->mnt_opts, *p;
+
+  while ((p = strstr (rest, opt)) != NULL)
+    {
+      if ((p == rest || p[-1] == ',')
+          && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ','))
+        return p;
+
+      rest = strchr (p, ',');
+      if (rest == NULL)
+        break;
+      ++rest;
+    }
+
+  return NULL;
+}
index 4da9d85314d7330af02e5704fceaa92dc7f5c292..c8750fec666d25a75744a902cb1cb829c271e8d1 100644 (file)
 #ifndef _@GUARD_PREFIX@_MNTENT_H
 #define _@GUARD_PREFIX@_MNTENT_H
 
+/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*.  */
+#if !_GL_CONFIG_H_INCLUDED
+ #error "Please include config.h first."
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
+#if @GNULIB_HASMNTOPT@ && @HAVE_SETMNTENT@
+/* Searches ME->mnt_opts for an option matching OPTION.
+   Returns the address of the substring, or null if none found.  */
+# if @REPLACE_HASMNTOPT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef hasmntopt
+#   define hasmntopt rpl_hasmntopt
+#  endif
+_GL_FUNCDECL_RPL (hasmntopt, char *,
+                  (const struct mntent *me, const char *option),
+                  _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (hasmntopt, char *,
+                  (const struct mntent *me, const char *option));
+# else
+#  if !@HAVE_HASMNTOPT@
+_GL_FUNCDECL_SYS (hasmntopt, char *,
+                  (const struct mntent *me, const char *option),
+                  _GL_ARG_NONNULL ((1, 2)));
+#  endif
+_GL_CXXALIAS_SYS (hasmntopt, char *,
+                  (const struct mntent *me, const char *option));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (hasmntopt);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef hasmntopt
+# if HAVE_RAW_DECL_HASMNTOPT
+_GL_WARN_ON_USE (hasmntopt, "hasmntopt is unportable - "
+                 "use gnulib module hasmntopt for portability");
+# endif
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/m4/hasmntopt.m4 b/m4/hasmntopt.m4
new file mode 100644 (file)
index 0000000..2dcaa7d
--- /dev/null
@@ -0,0 +1,75 @@
+# hasmntopt.m4
+# serial 1
+dnl Copyright (C) 2024 Free Software Foundation, Inc.
+dnl
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_HASMNTOPT],
+[
+  AC_REQUIRE([gl_MNTENT_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
+  gl_CHECK_FUNCS_ANDROID([setmntent],
+    [[#include <stdio.h>
+      #include <mntent.h>
+    ]])
+  if test $ac_cv_func_setmntent != yes; then
+    HAVE_SETMNTENT=0
+  fi
+
+  gl_CHECK_FUNCS_ANDROID([hasmntopt],
+    [[#include <stdio.h>
+      #include <mntent.h>
+    ]])
+  if test $ac_cv_func_hasmntopt = yes; then
+    dnl hasmntopt has the dumbest possible implementation on musl libc 1.2.5:
+    dnl it confuses the "atime" option with the "noatime" option.
+    AC_CACHE_CHECK([whether hasmntopt works],
+      [gl_cv_func_hasmntopt_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <mntent.h>
+              #include <stddef.h>
+            ]],
+            [[int result = 0;
+              /* This test fails on musl libc 1.2.5.  */
+              {
+                char options[] = "rw,noatime";
+                struct mntent me;
+                me.mnt_opts = options;
+                if (hasmntopt (&me, "atime") != NULL)
+                  result |= 1;
+              }
+              return result;
+            ]])
+         ],
+         [gl_cv_func_hasmntopt_works=yes],
+         [gl_cv_func_hasmntopt_works=no],
+         [case "$host_os" in
+                                # Guess yes on glibc systems.
+            *-gnu* | gnu*)      gl_cv_func_hasmntopt_works="guessing yes" ;;
+                                # Guess no on musl systems.
+            *-musl* | midipix*) gl_cv_func_hasmntopt_works="guessing no" ;;
+            *)                  gl_cv_func_hasmntopt_works="$gl_cross_guess_normal" ;;
+          esac
+         ])
+    ])
+    case "$gl_cv_func_hasmntopt_works" in
+      *yes) ;;
+      *)    REPLACE_HASMNTOPT=1 ;;
+    esac
+  else
+    HAVE_HASMNTOPT=0
+    case "$gl_cv_onwards_func_hasmntopt" in
+      future*) REPLACE_HASMNTOPT=1 ;;
+    esac
+  fi
+])
+
+# Prerequisites of lib/hasmntopt.c.
+AC_DEFUN([gl_PREREQ_HASMNTOPT],
+[
+  :
+])
index f067cd0293b33cba23ada31422824ab22e2af4e8..30eaee90c270d0fe38a497529049085d245cce1a 100644 (file)
@@ -1,5 +1,5 @@
 # mntent_h.m4
-# serial 1
+# serial 2
 dnl Copyright (C) 2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -20,6 +20,12 @@ AC_DEFUN_ONCE([gl_MNTENT_H],
   else
     GL_GENERATE_MNTENT_H=false
   fi
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <mntent.h>
+    ]],
+    [hasmntopt])
 ])
 
 # gl_MNTENT_MODULE_INDICATOR([modulename])
@@ -41,6 +47,7 @@ AC_DEFUN([gl_MNTENT_MODULE_INDICATOR],
 AC_DEFUN([gl_MNTENT_H_REQUIRE_DEFAULTS],
 [
   m4_defun(GL_MODULE_INDICATOR_PREFIX[_MNTENT_H_MODULE_INDICATOR_DEFAULTS], [
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_HASMNTOPT])
   ])
   m4_require(GL_MODULE_INDICATOR_PREFIX[_MNTENT_H_MODULE_INDICATOR_DEFAULTS])
   AC_REQUIRE([gl_MNTENT_H_DEFAULTS])
@@ -49,4 +56,7 @@ AC_DEFUN([gl_MNTENT_H_REQUIRE_DEFAULTS],
 AC_DEFUN([gl_MNTENT_H_DEFAULTS],
 [
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_HASMNTOPT=1;      AC_SUBST([HAVE_HASMNTOPT])
+  HAVE_SETMNTENT=1;      AC_SUBST([HAVE_SETMNTENT])
+  REPLACE_HASMNTOPT=0;   AC_SUBST([REPLACE_HASMNTOPT])
 ])
diff --git a/modules/hasmntopt b/modules/hasmntopt
new file mode 100644 (file)
index 0000000..6fdd897
--- /dev/null
@@ -0,0 +1,32 @@
+Description:
+hasmntopt() function: test for the presence of a mount option.
+
+Files:
+lib/hasmntopt.c
+m4/hasmntopt.m4
+
+Depends-on:
+mntent
+
+configure.ac:
+gl_FUNC_HASMNTOPT
+gl_CONDITIONAL([GL_COND_OBJ_HASMNTOPT],
+               [test $HAVE_SETMNTENT = 1 && { test $HAVE_HASMNTOPT = 0 || test $REPLACE_HASMNTOPT = 1; }])
+AM_COND_IF([GL_COND_OBJ_HASMNTOPT], [
+  gl_PREREQ_HASMNTOPT
+])
+gl_MNTENT_MODULE_INDICATOR([hasmntopt])
+
+Makefile.am:
+if GL_COND_OBJ_HASMNTOPT
+lib_SOURCES += hasmntopt.c
+endif
+
+Include:
+<mntent.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+glibc
index eb30116fad674cc8151ef2604d95e2a5696dba3c..8dc48c38d029cb42de1be91a4e49ba039ea8e4a8 100644 (file)
@@ -8,6 +8,9 @@ m4/mntent_h.m4
 Depends-on:
 gen-header
 include_next
+snippet/arg-nonnull
+snippet/c++defs
+snippet/warn-on-use
 
 configure.ac:
 gl_MNTENT_H
@@ -19,7 +22,7 @@ BUILT_SOURCES += $(MNTENT_H)
 
 # We need the following in order to create <mntent.h> when desired.
 if GL_GENERATE_MNTENT_H
-mntent.h: mntent.in.h $(top_builddir)/config.status
+mntent.h: mntent.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)$(MKDIR_P) '%reldir%'
        $(AM_V_at)$(SED_HEADER_STDOUT) \
              -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
@@ -27,6 +30,13 @@ mntent.h: mntent.in.h $(top_builddir)/config.status
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_MNTENT_H''@|$(NEXT_MNTENT_H)|g' \
+             -e 's/@''GNULIB_HASMNTOPT''@/$(GNULIB_HASMNTOPT)/g' \
+             -e 's|@''HAVE_HASMNTOPT''@|$(HAVE_HASMNTOPT)|g' \
+             -e 's|@''HAVE_SETMNTENT''@|$(HAVE_SETMNTENT)|g' \
+             -e 's|@''REPLACE_HASMNTOPT''@|$(REPLACE_HASMNTOPT)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              $(srcdir)/mntent.in.h > $@-t
        $(AM_V_at)mv $@-t $@
 else