From d84508cfbdba620d02e37dbd47c3065dfe7ab240 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 21 Jun 2011 14:58:37 +0200 Subject: libmount: allow to set parser callback to context Signed-off-by: Karel Zak --- libmount/src/context.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'libmount/src/context.c') diff --git a/libmount/src/context.c b/libmount/src/context.c index d65c8f152..f3eaae414 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -696,6 +696,8 @@ int mnt_context_get_fstab(struct libmnt_context *cxt, struct libmnt_table **tb) cxt->fstab = mnt_new_table(); if (!cxt->fstab) return -ENOMEM; + if (cxt->table_errcb) + mnt_table_set_parser_errcb(cxt->fstab, cxt->table_errcb); cxt->flags &= ~MNT_FL_EXTERN_FSTAB; rc = mnt_table_parse_fstab(cxt->fstab, NULL); if (rc) @@ -736,6 +738,8 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb) cxt->mtab = mnt_new_table(); if (!cxt->mtab) return -ENOMEM; + if (cxt->table_errcb) + mnt_table_set_parser_errcb(cxt->fstab, cxt->table_errcb); rc = mnt_table_parse_mtab(cxt->mtab, cxt->mtab_path); if (rc) return rc; @@ -749,6 +753,30 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb) return 0; } +/** + * mnt_context_set_tables_errcb + * @cxt: mount context + * @cb: pointer to callback function + * + * The error callback is used for all tab files (e.g. mtab, fstab) + * parsed within the context. + * + * See also mnt_context_get_mtab(), + * mnt_context_get_fstab(), + * mnt_table_set_parser_errcb(). + * + * Returns: 0 on success, negative number in case of error. + */ +int mnt_context_set_tables_errcb(struct libmnt_context *cxt, + int (*cb)(struct libmnt_table *tb, const char *filename, int line)) +{ + if (!cxt) + return -EINVAL; + + cxt->table_errcb = cb; + return 0; +} + /** * mnt_context_set_cache: * @cxt: mount context -- cgit v1.2.3-55-g7522