helper/fileio: Use size_t for file size. 97/2997/2
authorMarc Schink <openocd-dev@marcschink.de>
Fri, 2 Oct 2015 15:35:15 +0000 (17:35 +0200)
committerFreddie Chopin <freddie.chopin@gmail.com>
Tue, 3 Nov 2015 22:14:07 +0000 (22:14 +0000)
Change-Id: Ie116b44ba15e8ae41ca9ed4a354a82b2c4a92233
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/2997
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/flash/mflash.c
src/flash/nand/fileio.c
src/flash/nand/tcl.c
src/flash/nor/tcl.c
src/helper/fileio.c
src/helper/fileio.h
src/target/etm.c
src/target/image.c
src/target/target.c

index ea1673f..6f4a988 100644 (file)
@@ -761,7 +761,7 @@ COMMAND_HANDLER(mg_write_cmd)
        if (ret != ERROR_OK)
                return ret;
 
-       int filesize;
+       size_t filesize;
        buffer = malloc(MG_FILEIO_CHUNK);
        if (!buffer) {
                fileio_close(&fileio);
@@ -801,8 +801,8 @@ COMMAND_HANDLER(mg_write_cmd)
        }
 
        if (duration_measure(&bench) == ERROR_OK) {
-               command_print(CMD_CTX, "wrote %ld bytes from file %s "
-                       "in %fs (%0.3f kB/s)", (long)filesize, CMD_ARGV[1],
+               command_print(CMD_CTX, "wrote %zu bytes from file %s "
+                       "in %fs (%0.3f kB/s)", filesize, CMD_ARGV[1],
                        duration_elapsed(&bench), duration_kbps(&bench, filesize));
        }
 
index bc2a294..d84ef4f 100644 (file)
@@ -168,7 +168,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state,
                return retval;
 
        if (!need_size) {
-               int filesize;
+               size_t filesize;
                retval = fileio_size(&state->fileio, &filesize);
                if (retval != ERROR_OK)
                        return retval;
index 20854c7..750c1f0 100644 (file)
@@ -341,7 +341,7 @@ COMMAND_HANDLER(handle_nand_verify_command)
 
 COMMAND_HANDLER(handle_nand_dump_command)
 {
-       int filesize;
+       size_t filesize;
        struct nand_device *nand = NULL;
        struct nand_fileio_state s;
        int retval = CALL_COMMAND_HANDLER(nand_fileio_parse_args,
@@ -374,8 +374,8 @@ COMMAND_HANDLER(handle_nand_dump_command)
                return retval;
 
        if (nand_fileio_finish(&s) == ERROR_OK) {
-               command_print(CMD_CTX, "dumped %ld bytes in %fs (%0.3f KiB/s)",
-                       (long)filesize, duration_elapsed(&s.bench),
+               command_print(CMD_CTX, "dumped %zu bytes in %fs (%0.3f KiB/s)",
+                       filesize, duration_elapsed(&s.bench),
                        duration_kbps(&s.bench, filesize));
        }
        return ERROR_OK;
index 709d0c1..8a30e1c 100644 (file)
@@ -573,7 +573,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
        if (fileio_open(&fileio, CMD_ARGV[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
                return ERROR_OK;
 
-       int filesize;
+       size_t filesize;
        retval = fileio_size(&fileio, &filesize);
        if (retval != ERROR_OK) {
                fileio_close(&fileio);
@@ -599,9 +599,9 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
        buffer = NULL;
 
        if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
-               command_print(CMD_CTX, "wrote %ld bytes from file %s to flash bank %u"
+               command_print(CMD_CTX, "wrote %zu bytes from file %s to flash bank %u"
                        " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)",
-                       (long)filesize, CMD_ARGV[1], p->bank_number, offset,
+                       filesize, CMD_ARGV[1], p->bank_number, offset,
                        duration_elapsed(&bench), duration_kbps(&bench, filesize));
        }
 
@@ -676,7 +676,7 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
        uint8_t *buffer_file, *buffer_flash;
        struct fileio fileio;
        size_t read_cnt;
-       int filesize;
+       size_t filesize;
        int differ;
 
        if (CMD_ARGC != 3)
@@ -719,7 +719,7 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
                return retval;
        }
 
-       if (read_cnt != (size_t) filesize) {
+       if (read_cnt != filesize) {
                LOG_ERROR("Short read");
                free(buffer_file);
                return ERROR_FAIL;
index c6f45e6..9d39313 100644 (file)
@@ -34,7 +34,7 @@
 
 struct fileio_internal {
        char *url;
-       ssize_t size;
+       size_t size;
        enum fileio_type type;
        enum fileio_access access;
        FILE *file;
@@ -44,6 +44,7 @@ static inline int fileio_close_local(struct fileio_internal *fileio);
 static inline int fileio_open_local(struct fileio_internal *fileio)
 {
        char file_access[4];
+       ssize_t file_size;
 
        switch (fileio->access) {
                case FILEIO_READ:
@@ -78,6 +79,8 @@ static inline int fileio_open_local(struct fileio_internal *fileio)
                return ERROR_FILEIO_OPERATION_FAILED;
        }
 
+       file_size = 0;
+
        if ((fileio->access != FILEIO_WRITE) || (fileio->access == FILEIO_READWRITE)) {
                /* NB! Here we use fseek() instead of stat(), since stat is a
                 * more advanced operation that might not apply to e.g. a disk path
@@ -86,16 +89,17 @@ static inline int fileio_open_local(struct fileio_internal *fileio)
 
                result = fseek(fileio->file, 0, SEEK_END);
 
-               fileio->size = ftell(fileio->file);
+               file_size = ftell(fileio->file);
 
                result2 = fseek(fileio->file, 0, SEEK_SET);
 
-               if ((fileio->size < 0) || (result < 0) || (result2 < 0)) {
+               if ((file_size < 0) || (result < 0) || (result2 < 0)) {
                        fileio_close_local(fileio);
                        return ERROR_FILEIO_OPERATION_FAILED;
                }
-       } else
-               fileio->size = 0x0;
+       }
+
+       fileio->size = file_size;
 
        return ERROR_OK;
 }
@@ -245,9 +249,10 @@ int fileio_write_u32(struct fileio *fileio_p, uint32_t data)
  * Avoiding the seek on startup opens up for using streams.
  *
  */
-int fileio_size(struct fileio *fileio_p, int *size)
+int fileio_size(struct fileio *fileio_p, size_t *size)
 {
        struct fileio_internal *fileio = fileio_p->fp;
        *size = fileio->size;
+
        return ERROR_OK;
 }
index 680bdd2..c3824ff 100644 (file)
@@ -62,7 +62,7 @@ int fileio_write(struct fileio *fileio,
 
 int fileio_read_u32(struct fileio *fileio, uint32_t *data);
 int fileio_write_u32(struct fileio *fileio, uint32_t data);
-int fileio_size(struct fileio *fileio, int *size);
+int fileio_size(struct fileio *fileio, size_t *size);
 
 #define ERROR_FILEIO_LOCATION_UNKNOWN                  (-1200)
 #define ERROR_FILEIO_NOT_FOUND                                 (-1201)
index 5239190..ddeb922 100644 (file)
@@ -1788,7 +1788,7 @@ COMMAND_HANDLER(handle_etm_load_command)
        if (fileio_open(&file, CMD_ARGV[0], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
                return ERROR_FAIL;
 
-       int filesize;
+       size_t filesize;
        int retval = fileio_size(&file, &filesize);
        if (retval != ERROR_OK) {
                fileio_close(&file);
index b1b7e3a..fa51ce3 100644 (file)
@@ -130,7 +130,7 @@ static int image_ihex_buffer_complete_inner(struct image *image,
        /* we can't determine the number of sections that we'll have to create ahead of time,
         * so we locally hold them until parsing is finished */
 
-       int filesize;
+       size_t filesize;
        int retval;
        retval = fileio_size(fileio, &filesize);
        if (retval != ERROR_OK)
@@ -520,7 +520,7 @@ static int image_mot_buffer_complete_inner(struct image *image,
         * so we locally hold them until parsing is finished */
 
        int retval;
-       int filesize;
+       size_t filesize;
        retval = fileio_size(fileio, &filesize);
        if (retval != ERROR_OK)
                return retval;
@@ -707,7 +707,7 @@ int image_open(struct image *image, const char *url, const char *type_string)
                retval = fileio_open(&image_binary->fileio, url, FILEIO_READ, FILEIO_BINARY);
                if (retval != ERROR_OK)
                        return retval;
-               int filesize;
+               size_t filesize;
                retval = fileio_size(&image_binary->fileio, &filesize);
                if (retval != ERROR_OK) {
                        fileio_close(&image_binary->fileio);
index 2c30ce9..598d7d5 100644 (file)
@@ -3263,12 +3263,12 @@ COMMAND_HANDLER(handle_dump_image_command)
        free(buffer);
 
        if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
-               int filesize;
+               size_t filesize;
                retval = fileio_size(&fileio, &filesize);
                if (retval != ERROR_OK)
                        return retval;
                command_print(CMD_CTX,
-                               "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)filesize,
+                               "dumped %zu bytes in %fs (%0.3f KiB/s)", filesize,
                                duration_elapsed(&bench), duration_kbps(&bench, filesize));
        }