summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-03-18 03:56:17 +0100
committerDan McGee <dan@archlinux.org>2011-03-23 09:43:53 +0100
commit768451c5e3a9e8458ed646f965a9f091de6a4512 (patch)
treef82ae2116f280626b8d21ed680c34b4678af13e5 /lib
parentdb49c4a7f0145bd25ca570f23875065041d13aa4 (diff)
downloadpacman-768451c5e3a9e8458ed646f965a9f091de6a4512.tar.gz
pacman-768451c5e3a9e8458ed646f965a9f091de6a4512.tar.xz
lib/dload.c: fix compiler warnings generated by -Wfloat-equal
* introduces new macro in util.h (DOUBLE_EQ) for properly comparing floating point values Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/dload.c7
-rw-r--r--lib/libalpm/util.h4
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 4347e5db..8be69e8a 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -92,7 +92,7 @@ static int curl_progress(void *filename, double dltotal, double dlnow,
(void)ultotal;
(void)ulnow;
- if(dltotal == 0 || prevprogress == dltotal) {
+ if(DOUBLE_EQ(dltotal, 0) || DOUBLE_EQ(prevprogress, dltotal)) {
return 0;
}
@@ -230,7 +230,7 @@ static int curl_download_internal(const char *url, const char *localpath,
/* time condition was met and we didn't download anything. we need to
* clean up the 0 byte .part file that's left behind. */
- if(bytes_dl == 0 && timecond == 1) {
+ if(DOUBLE_EQ(bytes_dl, 0) && timecond == 1) {
ret = 1;
unlink(tempfile);
goto cleanup;
@@ -249,7 +249,8 @@ static int curl_download_internal(const char *url, const char *localpath,
/* remote_size isn't necessarily the full size of the file, just what the
* server reported as remaining to download. compare it to what curl reported
* as actually being transferred during curl_easy_perform() */
- if((remote_size != -1 && bytes_dl != -1) && bytes_dl != remote_size) {
+ if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) &&
+ !DOUBLE_EQ(bytes_dl, remote_size)) {
pm_errno = PM_ERR_RETRIEVE;
_alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
filename, (intmax_t)bytes_dl, (intmax_t)remote_size);
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 9f0344fe..1816e360 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -36,6 +36,8 @@
#include <time.h>
#include <sys/stat.h> /* struct stat */
#include <archive.h> /* struct archive */
+#include <math.h> /* fabs */
+#include <float.h> /* DBL_EPSILON */
#ifdef ENABLE_NLS
#include <libintl.h> /* here so it doesn't need to be included elsewhere */
@@ -61,6 +63,8 @@
_alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
return (ret); } while(0)
+#define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON)
+
/**
* Used as a buffer/state holder for _alpm_archive_fgets().
*/