summaryrefslogtreecommitdiffstats
path: root/libopkg
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-04-03 04:21:44 (EDT)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-04-03 04:21:44 (EDT)
commit33c7e93565efbb0c07d9aa0f8b72ca737111f338 (patch)
tree2c5c5c3515448f10b7eea284f9e1dca46be3d0e0 /libopkg
parent67d8721cc9b065a03e19c0495a2906a06017327a (diff)
Try to avoid long unsigned int overflow.
When free size is more than 4G, long unsigned int may enounter overflow git-svn-id: http://opkg.googlecode.com/svn/trunk@210 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg')
-rw-r--r--libopkg/opkg_utils.c24
-rw-r--r--libopkg/opkg_utils.h2
2 files changed, 17 insertions, 9 deletions
diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c
index 6a827e0..fb27b40 100644
--- a/libopkg/opkg_utils.c
+++ b/libopkg/opkg_utils.c
@@ -26,16 +26,24 @@
void print_pkg_status(pkg_t * pkg, FILE * file);
-int get_available_blocks(char * filesystem)
+long unsigned int get_available_blocks(char * filesystem)
{
- struct statfs sfs;
+ struct statfs sfs;
- if(statfs(filesystem, &sfs)){
- fprintf(stderr, "bad statfs\n");
- return 0;
- }
- /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
- return ((sfs.f_bavail * sfs.f_bsize) / 1024);
+ if(statfs(filesystem, &sfs)){
+ fprintf(stderr, "bad statfs\n");
+ return 0;
+ }
+ /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
+
+ // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024)
+ // and here we try to avoid overflow.
+ if (sfs.f_bsize >= 1024)
+ return (sfs.f_bavail * (sfs.f_bsize / 1024));
+ else if (sfs.f_bsize > 0)
+ return sfs.f_bavail / (1024 / sfs.f_bsize);
+ fprintf(stderr, "bad statfs f_bsize == 0\n");
+ return 0;
}
char **read_raw_pkgs_from_file(const char *file_name)
diff --git a/libopkg/opkg_utils.h b/libopkg/opkg_utils.h
index c3e90a9..226c7d1 100644
--- a/libopkg/opkg_utils.h
+++ b/libopkg/opkg_utils.h
@@ -25,7 +25,7 @@ void push_error_list(struct errlist **errors,char * msg);
void reverse_error_list(struct errlist **errors);
void free_error_list();
-int get_available_blocks(char * filesystem);
+long unsigned int get_available_blocks(char * filesystem);
char **read_raw_pkgs_from_file(const char *file_name);
char **read_raw_pkgs_from_stream(FILE *fp);
char *trim_alloc(char * line);