diff options
Diffstat (limited to 'src/flash/mflash.c')
-rw-r--r-- | src/flash/mflash.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/flash/mflash.c b/src/flash/mflash.c index 272127b..ba34422 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -720,14 +720,20 @@ COMMAND_HANDLER(mg_write_cmd) if (ret != ERROR_OK) return ret; + int filesize; buffer = malloc(MG_FILEIO_CHUNK); if (!buffer) { fileio_close(&fileio); return ERROR_FAIL; } + int retval = fileio_size(&fileio, &filesize); + if (retval != ERROR_OK) { + fileio_close(&fileio); + return retval; + } - cnt = fileio_size(&fileio) / MG_FILEIO_CHUNK; - res = fileio_size(&fileio) % MG_FILEIO_CHUNK; + cnt = filesize / MG_FILEIO_CHUNK; + res = filesize % MG_FILEIO_CHUNK; struct duration bench; duration_start(&bench); @@ -752,8 +758,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)fileio_size(&fileio), CMD_ARGV[1], - duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio))); + "in %fs (%0.3f kB/s)", (long)filesize, CMD_ARGV[1], + duration_elapsed(&bench), duration_kbps(&bench, filesize)); } free(buffer); |