Skip to content

Commit

Permalink
Fix tests involving reading/writing files failing on Windows
Browse files Browse the repository at this point in the history
The issue was that r and w without the b flag on Windows does LF and CR
translations when reading and writing. Not good for binary files.
  • Loading branch information
robinlinden committed Nov 21, 2020
1 parent 00f2f41 commit a71ddc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions auto_tests/file_saving_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void save_data_encrypted(void)

tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);

FILE *f = fopen(savefile, "w");
FILE *f = fopen(savefile, "wb");

size_t size = tox_get_savedata_size(t);
uint8_t *clear = (uint8_t *)malloc(size);
Expand Down Expand Up @@ -63,7 +63,7 @@ static void save_data_encrypted(void)

static void load_data_decrypted(void)
{
FILE *f = fopen(savefile, "r");
FILE *f = fopen(savefile, "rb");
ck_assert(f != nullptr);
fseek(f, 0, SEEK_END);
int64_t size = ftell(f);
Expand Down
4 changes: 2 additions & 2 deletions auto_tests/save_compatibility_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

static size_t get_file_size(const char *save_path)
{
FILE *const fp = fopen(save_path, "r");
FILE *const fp = fopen(save_path, "rb");

if (fp == nullptr) {
return 0;
Expand All @@ -42,7 +42,7 @@ static uint8_t *read_save(const char *save_path, size_t *length)
return nullptr;
}

FILE *const fp = fopen(save_path, "r");
FILE *const fp = fopen(save_path, "rb");

if (!fp) {
return nullptr;
Expand Down

0 comments on commit a71ddc7

Please sign in to comment.