summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shlibs/mount/src/mount.h.in1
-rw-r--r--shlibs/mount/src/mount.sym1
-rw-r--r--shlibs/mount/src/tab_parse.c84
3 files changed, 52 insertions, 34 deletions
diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in
index 8f1ecaad8..ac1aef403 100644
--- a/shlibs/mount/src/mount.h.in
+++ b/shlibs/mount/src/mount.h.in
@@ -265,6 +265,7 @@ extern int mnt_fs_print_debug(mnt_fs *ent, FILE *file);
/* tab-parse.c */
extern mnt_tab *mnt_new_tab_from_file(const char *filename);
+extern int mnt_tab_parse_stream(mnt_tab *tb, FILE *f, const char *filename);
extern int mnt_tab_parse_file(mnt_tab *tb, const char *filename);
extern int mnt_tab_set_parser_errcb(mnt_tab *tb,
int (*cb)(mnt_tab *tb, const char *filename, int line, int flag));
diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym
index 7cd794982..8f930967c 100644
--- a/shlibs/mount/src/mount.sym
+++ b/shlibs/mount/src/mount.sym
@@ -121,6 +121,7 @@ global:
mnt_tab_next_child_fs;
mnt_tab_next_fs;
mnt_tab_parse_file;
+ mnt_tab_parse_stream;
mnt_tab_remove_fs;
mnt_tab_set_cache;
mnt_tab_set_parser_errcb;
diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c
index 69443ca7a..d82be5aba 100644
--- a/shlibs/mount/src/tab_parse.c
+++ b/shlibs/mount/src/tab_parse.c
@@ -364,44 +364,21 @@ err:
}
/**
- * mnt_tab_parse_file:
+ * mnt_tab_parse_stream:
* @tb: tab pointer
- * @filename: file
- *
- * Parses whole table (e.g. /etc/fstab).
- *
- * <informalexample>
- * <programlisting>
- * mnt_tab *tb = mnt_new_tab();
- * int rc;
- *
- * rc = mnt_tab_parse_file(tb, "/etc/fstab");
- * if (!rc)
- * mnt_fprintf_tab(tb, stdout, NULL);
- * mnt_free_tab(tb);
- * </programlisting>
- * </informalexample>
- *
- * The libmount parser ignores broken (with syntax error) lines, these lines are
- * reported to caller by errcb() function (see mnt_tab_set_parser_errcb()).
+ * @f: file stream
+ * @filename: filename used for debug and error messages
*
* Returns: 0 on success, -1 in case of error.
*/
-int mnt_tab_parse_file(mnt_tab *tb, const char *filename)
+int mnt_tab_parse_stream(mnt_tab *tb, FILE *f, const char *filename)
{
- FILE *f;
int nlines = 0;
assert(tb);
+ assert(f);
assert(filename);
- if (!filename)
- return -1;
-
- f = fopen(filename, "r");
- if (!f)
- return -1;
-
DBG(DEBUG_TAB,
fprintf(stderr, "libmount: tab %p: start parsing %s\n", tb, filename));
@@ -427,22 +404,61 @@ int mnt_tab_parse_file(mnt_tab *tb, const char *filename)
DBG(DEBUG_TAB,
fprintf(stderr, "libmount: tab %p: stop parsing %s\n", tb, filename));
- fclose(f);
return 0;
error:
DBG(DEBUG_TAB,
fprintf(stderr, "libmount: tab %p: error parsing %s\n", tb, filename));
- fclose(f);
return -1;
}
/**
- * mnt_new_tab_parse:
+ * mnt_tab_parse_file:
+ * @tb: tab pointer
+ * @filename: file
+ *
+ * Parses whole table (e.g. /etc/fstab).
+ *
+ * <informalexample>
+ * <programlisting>
+ * mnt_tab *tb = mnt_new_tab();
+ * int rc;
+ *
+ * rc = mnt_tab_parse_file(tb, "/etc/fstab");
+ * if (!rc)
+ * mnt_fprintf_tab(tb, stdout, NULL);
+ * mnt_free_tab(tb);
+ * </programlisting>
+ * </informalexample>
+ *
+ * The libmount parser ignores broken (syntax error) lines, these lines are
+ * reported to caller by errcb() function (see mnt_tab_set_parser_errcb()).
+ *
+ * Returns: 0 on success, -1 in case of error.
+ */
+int mnt_tab_parse_file(mnt_tab *tb, const char *filename)
+{
+ FILE *f;
+ int rc = -1;
+
+ assert(tb);
+ assert(filename);
+
+ if (!filename || !tb)
+ return -1;
+
+ f = fopen(filename, "r");
+ if (f) {
+ rc = mnt_tab_parse_stream(tb, f, filename);
+ fclose(f);
+ }
+ return rc;
+}
+
+/**
+ * mnt_new_tab_from_file:
* @filename: /etc/{m,fs}tab or /proc/self/mountinfo path
*
- * Same as mnt_new_tab() + mnt_tab_parse_file(). Note that this function does
- * not provide details (by mnt_tab_strerror()) about failed parsing -- so you
- * should not to use this function for user-writeable files like /etc/fstab.
+ * Same as mnt_new_tab() + mnt_tab_parse_file().
*
* Returns: newly allocated tab on success and NULL in case of error.
*/