]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
build-sys: check scanf %ms modifier
authorKarel Zak <kzak@redhat.com>
Sat, 1 Oct 2011 13:33:53 +0000 (15:33 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Oct 2011 12:22:27 +0000 (14:22 +0200)
Without the check libmount builds on systems that has older than 2.7
glibc are silently unsuccessful.  The missing %ms modifier will, at
least, result on such system missing output of findmnt and lsblk
commands.  If either %ms or %as modifiers are present the libmount
build is disabled.

Based on patch from: Sami Kerola <kerolasa@iki.fi>

Signed-off-by: Karel Zak <kzak@redhat.com>
Conflicts:

include/c.h

configure.ac
include/c.h
libmount/src/tab_parse.c

index 52f1be07325a8bcf83d606d746fc8131169b68bb..8a6467f3085f6dfdfad83bb561e4e07aba2b8671 100644 (file)
@@ -458,6 +458,44 @@ elif test "x$enable_libmount" = xno; then
     build_libmount=no
 fi
 
+AC_DEFUN([UTIL_SCANF_TYPE_MODIFIER], [dnl
+# include <stdio.h>
+int main()
+{
+       int i;
+       char *s;
+       i = sscanf("x", $1, &s);
+       if (i == 1)
+               return 0;
+       return 1;
+}])
+AC_MSG_CHECKING([needed scanf type modifiers])
+AC_CACHE_VAL([scanf_cv_type_modifier],
+  AC_RUN_IFELSE([AC_LANG_SOURCE([UTIL_SCANF_TYPE_MODIFIER(["%ms"])])],
+    [scanf_cv_type_modifier=ms],
+    AC_RUN_IFELSE([AC_LANG_SOURCE([UTIL_SCANF_TYPE_MODIFIER(["%as"])])],
+      [scanf_cv_type_modifier=as],
+      [scanf_cv_type_modifier=no]
+    )
+  )
+)
+
+case "$scanf_cv_type_modifier" in
+ms)
+  AC_MSG_RESULT([(%ms) yes])
+  AC_DEFINE([HAVE_SCANF_MS_MODIFIER], [1], [scanf %ms modifier]) ;;
+as)
+  AC_MSG_RESULT([(%as) yes])
+  AC_DEFINE([HAVE_SCANF_AS_MODIFIER], [1], [scanf %as modifier]) ;;
+*)
+  AC_MSG_RESULT([no])
+  if "x$build_libmount" = xyes; then
+    AC_MSG_WARN([%as or %ms for sscanf() not found; do not build libmount])
+    build_libmount=no
+  fi
+esac
+
+
 case "$enable_libblkid:$build_libmount" in
 no:yes)
   AC_MSG_ERROR([cannot enable libmount when libblkid is disabled]) ;;
index df0b130d2b38abe8ef0b013e51a515d0481573f8..d50e4c4a5e0e89012795b2384a59c2f0e399c00b 100644 (file)
@@ -211,4 +211,13 @@ static inline int dirfd(DIR *d)
 #define IUTF8 0040000
 #endif
 
+/*
+ * scanf modifiers for "strings allocation"
+ */
+#ifdef HAVE_SCANF_MS_MODIFIER
+#define UL_SCNsA       "%ms"
+#elif defined(HAVE_SCANF_AS_MODIFIER)
+#define UL_SCNsA       "%as"
+#endif
+
 #endif /* UTIL_LINUX_C_H */
index dba60028ab28ab0bc5f73ca6674b69f2b7661026..18a12434592ce86bd77047e96832bd2bebc3e352 100644 (file)
@@ -54,11 +54,12 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s)
        int rc, n = 0;
        char *src, *fstype, *optstr;
 
-       rc = sscanf(s,  "%ms "  /* (1) source */
-                       "%ms "  /* (2) target */
-                       "%ms "  /* (3) FS type */
-                       "%ms "  /* (4) options */
-                       "%n",   /* byte count */
+       rc = sscanf(s,  UL_SCNsA" "     /* (1) source */
+                       UL_SCNsA" "     /* (2) target */
+                       UL_SCNsA" "     /* (3) FS type */
+                       UL_SCNsA" "     /* (4) options */
+                       "%n",           /* byte count */
+
                        &src,
                        &fs->target,
                        &fstype,
@@ -114,9 +115,9 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s)
        rc = sscanf(s,  "%u "           /* (1) id */
                        "%u "           /* (2) parent */
                        "%u:%u "        /* (3) maj:min */
-                       "%ms "          /* (4) mountroot */
-                       "%ms "          /* (5) target */
-                       "%ms"           /* (6) vfs options (fs-independent) */
+                       UL_SCNsA" "     /* (4) mountroot */
+                       UL_SCNsA" "     /* (5) target */
+                       UL_SCNsA        /* (6) vfs options (fs-independent) */
                        "%n",           /* number of read bytes */
 
                        &fs->id,
@@ -138,9 +139,9 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s)
        }
        s = p + 3;
 
-       rc += sscanf(s, "%ms "          /* (8) FS type */
-                       "%ms "          /* (9) source */
-                       "%ms",          /* (10) fs options (fs specific) */
+       rc += sscanf(s, UL_SCNsA" "     /* (8) FS type */
+                       UL_SCNsA" "     /* (9) source */
+                       UL_SCNsA,       /* (10) fs options (fs specific) */
 
                        &fstype,
                        &src,