diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2014-04-26 18:40:40 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-01-21 05:27:47 +0100 |
commit | 3b20561748ff6b36ae99ff4fc1829035240cba33 (patch) | |
tree | 68af590857c5851c7dd1f745dd28b93bd0f478ad /src/pacman/ini.c | |
parent | ea96b567221e1426c6f6ab2b31891d1301fd00f4 (diff) | |
download | pacman-3b20561748ff6b36ae99ff4fc1829035240cba33.tar.gz pacman-3b20561748ff6b36ae99ff4fc1829035240cba33.tar.xz |
ini.c: move error output into conf.c
Move the remaining output into conf.c by notifying the callback of read
errors.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Diffstat (limited to 'src/pacman/ini.c')
-rw-r--r-- | src/pacman/ini.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/pacman/ini.c b/src/pacman/ini.c index affab54a..ca1363f1 100644 --- a/src/pacman/ini.c +++ b/src/pacman/ini.c @@ -33,12 +33,15 @@ * @param cb callback for key/value pairs * @param data caller defined data to be passed to the callback * - * @return 0 on success, 1 on parsing errors, the callback return value - * otherwise + * @return the callback return value * * @note The callback will be called at the beginning of each section with an * empty key and value and for each key/value pair. * + * @note If the parser encounters an error the callback will be called with + * section, key, and value set to NULL and errno set by fopen, fgets, or + * strdup. + * * @note The @a key and @a value passed to @ cb will be overwritten between * calls. The section name will remain valid until after @a cb is called to * begin a new section. @@ -52,13 +55,9 @@ int parse_ini(const char *file, ini_parser_fn cb, void *data) int linenum = 0; int ret = 0; - pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file); fp = fopen(file, "r"); if(fp == NULL) { - pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"), - file, strerror(errno)); - ret = 1; - goto cleanup; + return cb(file, 0, NULL, NULL, NULL, data); } while(safe_fgets(line, PATH_MAX, fp)) { @@ -109,11 +108,8 @@ int parse_ini(const char *file, ini_parser_fn cb, void *data) } cleanup: - if(fp) { - fclose(fp); - } + fclose(fp); free(section_name); - pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file); return ret; } |