if (ret != ERROR_OK)
return ret;
- int filesize;
+ size_t filesize;
buffer = malloc(MG_FILEIO_CHUNK);
if (!buffer) {
fileio_close(&fileio);
}
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));
}
return retval;
if (!need_size) {
- int filesize;
+ size_t filesize;
retval = fileio_size(&state->fileio, &filesize);
if (retval != ERROR_OK)
return retval;
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,
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;
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);
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));
}
uint8_t *buffer_file, *buffer_flash;
struct fileio fileio;
size_t read_cnt;
- int filesize;
+ size_t filesize;
int differ;
if (CMD_ARGC != 3)
return retval;
}
- if (read_cnt != (size_t) filesize) {
+ if (read_cnt != filesize) {
LOG_ERROR("Short read");
free(buffer_file);
return ERROR_FAIL;
struct fileio_internal {
char *url;
- ssize_t size;
+ size_t size;
enum fileio_type type;
enum fileio_access access;
FILE *file;
static inline int fileio_open_local(struct fileio_internal *fileio)
{
char file_access[4];
+ ssize_t file_size;
switch (fileio->access) {
case FILEIO_READ:
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
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;
}
* 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;
}
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)
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);
/* 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)
* 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;
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);
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));
}