From 7a3f59cd66a4f70641b863ebaaf52674b921bf3c Mon Sep 17 00:00:00 2001
From: Allan McRae <allan@archlinux.org>
Date: Sat, 11 Feb 2012 16:17:59 +1000
Subject: Reset errno before opening archive

Set errno to 0 at the start of _alpm_open_archive as it is not set when
archive_read_open_fd fails.  This can result in _alpm_pkg_load_internal
thinking errno == ENOENT and setting the wrong pm_errno. e.g.

Before:
> testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig
error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format
Cannot find the given file.

After:
> testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig
error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format
Cannot open the given file.

Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
---
 lib/libalpm/util.c | 1 +
 1 file changed, 1 insertion(+)

(limited to 'lib')

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 11285896..59861242 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -227,6 +227,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path,
 {
 	int fd;
 	size_t bufsize = ALPM_BUFFER_SIZE;
+	errno = 0;
 
 	if((*archive = archive_read_new()) == NULL) {
 		RET_ERR(handle, ALPM_ERR_LIBARCHIVE, -1);
-- 
cgit v1.2.3-2-g168b