]> git.sur5r.net Git - openocd/commitdiff
helper/fileio: Use size_t for file size.
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 ea1673f09d47282e7d4d5d7775df188c8491e251..6f4a988ece4de275fa5d5185a79072c45e646304 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 bc2a294226d4fa4b46f436d40dfd3bd249b594f5..d84ef4f943759d53e3d2638cf5b4b42122d51e77 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 20854c795e55c2a35391c3a67910ec92604e5f69..750c1f005fde42503e6ea08f4b33cb2b19a9056e 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 709d0c1a708906d1d350ef5c8d7f58e7959e2f9a..8a30e1cd995a95eb43755b2f6a904d30de100ed7 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 c6f45e6ba78bb23d8dec0bcdb00abe2b5ee4ed15..9d3931356e706120aa67f57febcd5ccda1f2d41c 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 680bdd2b82d0cd23820f3a23476731b756f4ad7c..c3824ff8fe9bd358598b730b4717fda01a1b83de 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 5239190a535e6b737130c1c1a1878b239cb3522e..ddeb9226e501ebe5b381fb22fa4462d60c833d6e 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 b1b7e3a6af723eeeb330d0526bafb4e7ae3827ed..fa51ce33e49de5f937267c42efd97e122fe5551e 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 2c30ce91e9f66f00b8b4499bb149028c60e9209a..598d7d5a8043303b4ddbef21082c19bd9e7cb262 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));
        }