From 0669c9bfac7aead01f1400444e691d542f7645c2 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 1 Jun 2008 21:47:31 -0500 Subject: Use correct C type for file sizes We have been using unsigned long as a file size type for a while, which works but isn't quite correct and could easily break. Worse was probably our use of int in the download callback functions, which could be restrictive for packages > 2GB in size. Switch all file size variables to use off_t, which is the preferred type for file sizes. Note that at least on Linux, all applications compiled against libalpm must now be sure to use large file support, where _FILE_OFFSET_BITS is defined to be 64 or there will be some weird issues that crop up. Signed-off-by: Dan McGee --- lib/libalpm/add.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/libalpm/add.c') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index c5454bab..03698622 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -27,6 +27,8 @@ #include #include #include +#include /* int64_t */ +#include /* intmax_t */ /* libarchive */ #include @@ -635,7 +637,6 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count, int i, ret = 0, errors = 0; char scriptlet[PATH_MAX+1]; int is_upgrade = 0; - double percent = 0.0; pmpkg_t *oldpkg = NULL; ALPM_LOG_FUNC; @@ -730,17 +731,22 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count, } for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) { + double percent; + if(newpkg->size != 0) { /* Using compressed size for calculations here, as newpkg->isize is not * exact when it comes to comparing to the ACTUAL uncompressed size * (missing metadata sizes) */ - unsigned long pos = archive_position_compressed(archive); + int64_t pos = archive_position_compressed(archive); percent = (double)pos / (double)newpkg->size; - _alpm_log(PM_LOG_DEBUG, "decompression progress: %f%% (%ld / %ld)\n", - percent*100.0, pos, newpkg->size); + _alpm_log(PM_LOG_DEBUG, "decompression progress: " + "%f%% (%"PRId64" / %jd)\n", + percent*100.0, pos, (intmax_t)newpkg->size); if(percent >= 1.0) { percent = 1.0; } + } else { + percent = 0.0; } if(is_upgrade) { -- cgit v1.2.3-70-g09d2