diff options
-rw-r--r-- | configure.ac | 38 | ||||
-rw-r--r-- | include/c.h | 9 | ||||
-rw-r--r-- | libmount/src/tab_parse.c | 23 |
3 files changed, 59 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index d12a4a037..88aced94f 100644 --- a/configure.ac +++ b/configure.ac @@ -477,6 +477,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]) ;; diff --git a/include/c.h b/include/c.h index 259e6b6cc..c4a95aa2b 100644 --- a/include/c.h +++ b/include/c.h @@ -224,4 +224,13 @@ static inline int dirfd(DIR *d) #define UTIL_LINUX_VERSION _("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING +/* + * 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 */ diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index dba60028a..18a124345 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -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, |