Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/diskspace.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-09 20:36:42 -0600
committerDan McGee <dan@archlinux.org>2011-01-10 10:49:55 -0600
commitd03b57f459fb9ab9288991a70c4e7297a7c1d150 (patch)
tree6bebc7f9ca3c5414a48dc1b5cfa323fd5c00e372 /lib/libalpm/diskspace.c
parent281a4c0a4f2de217b5d23939fb78b3bbfccc34ca (diff)
Remove need for floating point division in backend
All of these can be done with integer division; the only slightly interesting part is ensuring we round up like before with calling the ceil() function. We can also remove the math library from requirements; now that the only ceil() calls are gone, we don't need this anymore. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/diskspace.c')
-rw-r--r--lib/libalpm/diskspace.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index 87dca84f..b53d272f 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -38,8 +38,6 @@
#include <sys/types.h>
#endif
-#include <math.h>
-
/* libarchive */
#include <archive.h>
#include <archive_entry.h>
@@ -178,8 +176,9 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
}
data = mp->data;
- data->blocks_needed -= (long)ceil((double)(st.st_size) /
- (double)(data->fsp.f_bsize));
+ /* the addition of (divisor - 1) performs ceil() with integer division */
+ data->blocks_needed -=
+ (st.st_size + data->fsp.f_bsize - 1) / data->fsp.f_bsize;
data->used = 1;
}
@@ -229,8 +228,9 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
}
data = mp->data;
- data->blocks_needed += (long)ceil((double)(archive_entry_size(entry)) /
- (double)(data->fsp.f_bsize));
+ /* the addition of (divisor - 1) performs ceil() with integer division */
+ data->blocks_needed +=
+ (archive_entry_size(entry) + data->fsp.f_bsize - 1) / data->fsp.f_bsize;
data->used = 1;
}
@@ -259,8 +259,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
if(replaces) {
numtargs += replaces;
for(targ = trans->remove; targ; targ = targ->next, current++) {
- double percent = (double)current / (double)numtargs;
- PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100),
+ int percent = (current * 100) / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current);
pkg = targ->data;
@@ -269,8 +269,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
}
for(targ = trans->add; targ; targ = targ->next, current++) {
- double percent = (double)current / (double)numtargs;
- PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100),
+ int percent = (current * 100) / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current);
pkg = targ->data;