Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=deb822985dc586c72a975fa74ddb415925572da6

commit deb822985dc586c72a975fa74ddb415925572da6
Author: Michel Hermier <herm...@frugalware.org>
Date:   Sat Nov 16 11:56:18 2013 +0100

libpacman: Change pacman_downloadstate_* to output values by pointer arguments.

diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c
index 7b3fb1c..4f833ec 100644
--- a/lib/libpacman/pacman.c
+++ b/lib/libpacman/pacman.c
@@ -432,46 +432,58 @@ int pacman_downloadstate_begin(const pmdownloadstate_t 
*downloadstate, struct ti

/** Get the size at the start of the download resume
* @param downloadstate pointer to the download state to get the informations 
from.
- * @return the size of the file at the start of download resume of the file or 
((off_t) -1) in case of error.
+ * @param offset pointer to the value to be written.
+ * @return return 0 in case of success, not 0 otherwise.
*/
-off_t pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate)
+int pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate, off_t 
*offset)
{
-       ASSERT(downloadstate != NULL, return((off_t) -1));
+       ASSERT(downloadstate != NULL, return -1);
+       ASSERT(offset != NULL, return -1);

-       return downloadstate->dst_resume;
+       *offset = downloadstate->dst_resume;
+       return 0;
}

/** Get the final size of the download
* @param downloadstate pointer to the download state to get the informations 
from.
- * @return the size of the file or ((off_t) -1) in case of error.
+ * @param offset pointer to the value to be written.
+ * @return return 0 in case of success, not 0 otherwise.
*/
-off_t pacman_downloadstate_size(const pmdownloadstate_t *downloadstate)
+int pacman_downloadstate_size(const pmdownloadstate_t *downloadstate, off_t 
*offset)
{
-       ASSERT(downloadstate != NULL, return((off_t) -1));
+       ASSERT(downloadstate != NULL, return -1);
+       ASSERT(offset != NULL, return -1);

-       return downloadstate->dst_size;
+       *offset = downloadstate->dst_size;
+       return 0;
}

/** Get the current size of the download
* @param downloadstate pointer to the download state to get the informations 
from.
- * @return the current size of the file or ((off_t) -1) in case of error.
+ * @param offset pointer to the value to be written.
+ * @return return 0 in case of success, not 0 otherwise.
*/
-off_t pacman_downloadstate_tell(const pmdownloadstate_t *downloadstate)
+int pacman_downloadstate_tell(const pmdownloadstate_t *downloadstate, off_t 
*offset)
{
-       ASSERT(downloadstate != NULL, return((off_t) -1));
+       ASSERT(downloadstate != NULL, return -1);
+       ASSERT(offset != NULL, return -1);

-       return downloadstate->dst_tell;
+       downloadstate->dst_tell;
+       return 0;
}

/** Get the xfered size of the download
* @param downloadstate pointer to the download state to get the informations 
from.
- * @return the xfered size of the file or ((off_t) -1) in case of error.
+ * @param offset pointer to the value to be written.
+ * @return return 0 in case of success, not 0 otherwise.
*/
-off_t pacman_downloadstate_xfered(const pmdownloadstate_t *downloadstate)
+int pacman_downloadstate_xfered(const pmdownloadstate_t *downloadstate, off_t 
*offset)
{
-       ASSERT(downloadstate != NULL, return((off_t) -1));
+       ASSERT(downloadstate != NULL, return -1);
+       ASSERT(offset != NULL, return -1);

-       return downloadstate->dst_tell - downloadstate->dst_resume;
+       *offset = downloadstate->dst_tell - downloadstate->dst_resume;
+       return 0;
}

/** @} */
diff --git a/lib/libpacman/pacman.h b/lib/libpacman/pacman.h
index 6e01375..ed16fe5 100644
--- a/lib/libpacman/pacman.h
+++ b/lib/libpacman/pacman.h
@@ -173,10 +173,10 @@ pmlist_t *pacman_db_test(pmdb_t *db);
*/

int pacman_downloadstate_begin(const pmdownloadstate_t *downloadstate, struct 
timeval *timeval);
-off_t pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate);
-off_t pacman_downloadstate_size(const pmdownloadstate_t *downloadstate);
-off_t pacman_downloadstate_tell(const pmdownloadstate_t *downloadstate);
-off_t pacman_downloadstate_xfered(const pmdownloadstate_t *downloadstate);
+int pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate, off_t 
*offset);
+int pacman_downloadstate_size(const pmdownloadstate_t *downloadstate, off_t 
*offset);
+int pacman_downloadstate_tell(const pmdownloadstate_t *downloadstate, off_t 
*offset);
+int pacman_downloadstate_xfered(const pmdownloadstate_t *downloadstate, off_t 
*offset);

/*
* Packages
diff --git a/src/pacman-g2/download.c b/src/pacman-g2/download.c
index b78cd9f..b595b4d 100644
--- a/src/pacman-g2/download.c
+++ b/src/pacman-g2/download.c
@@ -54,10 +54,8 @@ extern unsigned int maxcols;
/* FIXME: log10() want float */
int log_progress(const pmdownloadstate_t *downloadstate)
{
-       int offset = pacman_downloadstate_resume(downloadstate);
-       int fsz = pacman_downloadstate_size(downloadstate);
-       int xfered = pacman_downloadstate_xfered(downloadstate);
-       int pct = ((float)(xfered+offset) / fsz) * 100;
+       off_t offset, fsz, xfered;
+       int pct;
static int lastpct=0;
unsigned int i, cur;
struct timeval t1;
@@ -71,6 +69,12 @@ int log_progress(const pmdownloadstate_t *downloadstate)
unsigned int maxpkglen;
static char prev_fnm[DLFNM_PROGRESS_LEN+1]="";

+       pacman_downloadstate_resume(downloadstate, &offset);
+       pacman_downloadstate_size(downloadstate, &fsz);
+       pacman_downloadstate_xfered(downloadstate, &xfered);
+
+       pct = ((float)(xfered+offset) / fsz) * 100;
+
if(config->dl_interrupted) {
printf("\n");
return 0;
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to