From 336f290a45e0428638e0649e10d4c7a126a9eeb2 Mon Sep 17 00:00:00 2001 From: duodenim Date: Sat, 14 Jan 2017 12:25:30 -0600 Subject: [PATCH] Use binary mode for flash read/writes (#58) use binary mode for flash read/writes use binary mode for vmu read/writes --- src/hw/maple/vmu.c | 4 ++-- src/hw/rom/flash.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hw/maple/vmu.c b/src/hw/maple/vmu.c index ac58fd6a..2be674a7 100644 --- a/src/hw/maple/vmu.c +++ b/src/hw/maple/vmu.c @@ -29,7 +29,7 @@ static void vmu_write_bin(int block, int phase, const void *buffer, int offset = VMU_BLOCK_OFFSET(block, phase); int size = num_words << 2; - FILE *file = fopen(vmu_path, "r+"); + FILE *file = fopen(vmu_path, "r+b"); CHECK_NOTNULL(file, "Failed to open %s", vmu_path); int r = fseek(file, offset, SEEK_SET); CHECK_NE(r, -1); @@ -43,7 +43,7 @@ static void vmu_read_bin(int block, int phase, void *buffer, int num_words) { int offset = VMU_BLOCK_OFFSET(block, phase); int size = num_words << 2; - FILE *file = fopen(vmu_path, "r"); + FILE *file = fopen(vmu_path, "rb"); CHECK_NOTNULL(file, "Failed to open %s", vmu_path); int r = fseek(file, offset, SEEK_SET); CHECK_NE(r, -1); diff --git a/src/hw/rom/flash.c b/src/hw/rom/flash.c index 4c5bb551..cd8e1a3e 100644 --- a/src/hw/rom/flash.c +++ b/src/hw/rom/flash.c @@ -40,7 +40,7 @@ const char *flash_bin_path() { static void flash_read_bin(int offset, void *buffer, int size) { const char *flash_path = flash_bin_path(); - FILE *file = fopen(flash_path, "r"); + FILE *file = fopen(flash_path, "rb"); CHECK_NOTNULL(file, "Failed to open %s", flash_path); int r = fseek(file, offset, SEEK_SET); CHECK_NE(r, -1); @@ -51,7 +51,7 @@ static void flash_read_bin(int offset, void *buffer, int size) { static void flash_write_bin(int offset, const void *buffer, int size) { const char *flash_path = flash_bin_path(); - FILE *file = fopen(flash_path, "r+"); + FILE *file = fopen(flash_path, "r+b"); CHECK_NOTNULL(file, "Failed to open %s", flash_path); int r = fseek(file, offset, SEEK_SET); CHECK_NE(r, -1); @@ -72,7 +72,7 @@ static int flash_init_bin() { LOG_INFO("Initializing flash rom from %s", OPTION_flash); - FILE *src = fopen(OPTION_flash, "r"); + FILE *src = fopen(OPTION_flash, "rb"); if (!src) { LOG_WARNING("Failed to load %s", OPTION_flash); return 0; @@ -93,7 +93,7 @@ static int flash_init_bin() { fclose(src); /* and copy it to the app directory */ - FILE *dst = fopen(flash_path, "w"); + FILE *dst = fopen(flash_path, "wb"); CHECK_NOTNULL("Failed to open %s", flash_path); int r = (int)fwrite(rom, 1, size, dst); CHECK_EQ(r, size);