Skip to content

Commit ee294cc

Browse files
committed
windows: handle binary files correctly.
1 parent daa6bfa commit ee294cc

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/analysis/FatExtract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void FatExtract::onEntry(FatEntry &parent, FatEntry &entry, string name)
4242

4343
string target = targetDirectory + name;
4444
cout << "Extracting " << name << " to " << target << endl;
45-
FILE *output = fopen(target.c_str(), "w+");
45+
FILE *output = fopen(target.c_str(), "wb+");
4646
system.readFile(entry.cluster, entry.size, output, contiguous);
4747
fclose(output);
4848

src/core/FatSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ FatSystem::FatSystem(string filename_, unsigned long long globalOffset_, OutputF
3838
rootEntries(0)
3939
{
4040
this->_outputFormat = outputFormat_;
41-
fd = open(filename.c_str(), O_RDONLY|O_LARGEFILE);
41+
fd = open(filename.c_str(), O_RDONLY | O_LARGEFILE | O_BINARY);
4242
writeMode = false;
4343

4444
if (fd < 0) {
@@ -64,7 +64,7 @@ void FatSystem::enableCache()
6464
void FatSystem::enableWrite()
6565
{
6666
close(fd);
67-
fd = open(filename.c_str(), O_RDWR|O_LARGEFILE);
67+
fd = open(filename.c_str(), O_RDWR | O_LARGEFILE | O_BINARY);
6868

6969
if (fd < 0) {
7070
ostringstream oss;

src/core/FatSystem.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
#include "FatPath.h"
1010
#include "OutputFormatType.h"
1111

12-
#ifdef __APPLE__
12+
#if defined(__APPLE__) || defined(_WIN32)
1313
#define O_LARGEFILE 0
1414
#define lseek64 lseek
1515
#endif
16-
#ifdef _WIN32
17-
#define O_LARGEFILE 0
18-
#define lseek64 lseek
16+
17+
#ifndef O_BINARY
18+
#define O_BINARY 0
1919
#endif
20+
2021
using namespace std;
2122

2223
// Last cluster

src/table/FatBackup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void FatBackup::backup(string backupFile, int fat)
2020
int size = system.fatSize;
2121
int n = 0;
2222
int offset = 0;
23-
FILE *backup = fopen(backupFile.c_str(), "w+");
23+
FILE *backup = fopen(backupFile.c_str(), "wb+");
2424

2525
if (fat == 0) {
2626
size *= 2;
@@ -55,7 +55,7 @@ void FatBackup::patch(string backupFile, int fat)
5555
char buffer[CHUNKS_SIZES];
5656

5757
// Opening the file
58-
FILE *backup = fopen(backupFile.c_str(), "r");
58+
FILE *backup = fopen(backupFile.c_str(), "rb");
5959
if (backup == NULL) {
6060
ostringstream oss;
6161
oss << "Unable to open file " << backupFile << " for reading";

0 commit comments

Comments
 (0)