Fix progress report for larger than 2GB file
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 10 Apr 2017 07:38:43 +0000 (16:38 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 11 Apr 2017 03:54:25 +0000 (12:54 +0900)
Currently, progress report function has 32bit signed value for its
send and left parameters, so it causes negative value progress. This
fixes the parameters as unsigned 32bit type to report properly.

Change-Id: I1d291c1507170c57b025d4fbd91098b48a97cdd0
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
libthor/thor.h
lthor.c

index 130f505dcc5650eaf5d71b0493a2baad2de19c1f..213a8b225c4bcb6d1a63908f72dcfe8ea76a0ede 100644 (file)
@@ -58,8 +58,8 @@ enum thor_data_src_format {
 
 typedef void (*thor_progress_cb)(thor_device_handle *th,
                                 struct thor_data_src *data,
-                                int sent, int left, int chunk_nmb,
-                                void *user_data);
+                                unsigned int sent, unsigned int left,
+                                int chunk_nmb, void *user_data);
 
 typedef void (*thor_next_entry_cb)(thor_device_handle *th,
                                 struct thor_data_src *data,
diff --git a/lthor.c b/lthor.c
index db429022c6170bdfce57f8104ce4acfaa7536d15..268e8074a0bceafa5497a32a140d0289b7477922 100644 (file)
--- a/lthor.c
+++ b/lthor.c
@@ -174,19 +174,20 @@ static double timediff(struct timeval *atv, struct timeval *btv)
 }
 
 static void report_progress(thor_device_handle *th, struct thor_data_src *data,
-                           int sent, int left, int chunk_nmb, void *user_data)
+                           unsigned int sent, unsigned int left, int chunk_nmb,
+                           void *user_data)
 {
        struct time_data *tdata = user_data;
        struct timeval *start_time = &tdata->start_time;
        struct timeval *last_time = &tdata->last_time;
        struct timeval current_time;
        double diff;
-       int sent_kb = sent/KB;
-       int total_kb = (sent + left)/KB;
+       unsigned int sent_kb = sent/KB;
+       unsigned int total_kb = (sent + left)/KB;
        char progress [4] = { '-', '\\', '|', '/' };
        char c = progress[(sent_kb/30)%4];
 
-       fprintf(stderr, "\x1b[1A\x1b[16C%c sending %6dk/%6dk %3d%% block %-6d",
+       fprintf(stderr, "\x1b[1A\x1b[16C%c sending %6uk/%6uk %3u%% block %-6d",
                c, sent_kb, total_kb, ((sent_kb*100)/total_kb), chunk_nmb);
 
        gettimeofday(&current_time, NULL);