From 821ff061b181d009e0633e5ab12aec7aa608884a Mon Sep 17 00:00:00 2001 From: Sebastian Nowicki Date: Sun, 12 Sep 2010 22:01:14 +0800 Subject: Set pm_errno on libarchive errors while reading Signed-off-by: Sebastian Nowicki Signed-off-by: Dan McGee --- lib/libalpm/package.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 0060300c..717d32ce 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -488,12 +488,15 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg) /** * Read data from an open changelog 'file stream'. Similar to fread in - * functionality, this function takes a buffer and amount of data to read. + * functionality, this function takes a buffer and amount of data to read. If an + * error occurs pm_errno will be set. + * * @param ptr a buffer to fill with raw changelog data * @param size the size of the buffer * @param pkg the package that the changelog is being read from * @param fp a 'file stream' to the package changelog - * @return the number of characters read, or 0 if there is no more data + * @return the number of characters read, or 0 if there is no more data or an + * error occurred. */ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, const pmpkg_t *pkg, const void *fp) @@ -502,7 +505,14 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, if(pkg->origin == PKG_FROM_CACHE) { ret = fread(ptr, 1, size, (FILE*)fp); } else if(pkg->origin == PKG_FROM_FILE) { - ret = archive_read_data((struct archive*)fp, ptr, size); + ssize_t sret = archive_read_data((struct archive*)fp, ptr, size); + /* Report error (negative values) */ + if(sret < 0) { + pm_errno = PM_ERR_LIBARCHIVE; + ret = 0; + } else { + ret = (size_t)sret; + } } return(ret); } -- cgit v1.2.3-24-g4f1b