diff options
author | Karel Zak | 2010-06-22 11:52:36 +0200 |
---|---|---|
committer | Karel Zak | 2011-01-03 12:28:39 +0100 |
commit | 45d6713e8781e3102fa49c4284637dc5fcf5f656 (patch) | |
tree | ec179af6008f66d9e5a6efd5b8c102a47adde245 /shlibs/mount/src/tab_parse.c | |
parent | libmount: don't store filename to mnt_tab (diff) | |
download | kernel-qcow2-util-linux-45d6713e8781e3102fa49c4284637dc5fcf5f656.tar.gz kernel-qcow2-util-linux-45d6713e8781e3102fa49c4284637dc5fcf5f656.tar.xz kernel-qcow2-util-linux-45d6713e8781e3102fa49c4284637dc5fcf5f656.zip |
libmount: add mnt_tab_parse_stream()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/tab_parse.c')
-rw-r--r-- | shlibs/mount/src/tab_parse.c | 84 |
1 files changed, 50 insertions, 34 deletions
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. */ |