helper/fileio: Use size_t for file size.
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>__archive__
parent
0578e4c4f4
commit
24d9f0cfa0
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue