Skip to content

Commit 31d052c

Browse files
authored
Merge pull request #372 from JagoGyselinck/master
Add O_BINARY flag when opening files to allow compilation for Windows
2 parents 8f5ac59 + 676326c commit 31d052c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/patchelf.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
#define PACKAGE_STRING "patchelf"
4848
#endif
4949

50+
// This is needed for Windows/mingw
51+
#ifndef O_BINARY
52+
#define O_BINARY 0
53+
#endif
54+
5055
static bool debugMode = false;
5156

5257
static bool forceRPath = false;
@@ -164,7 +169,7 @@ static FileContents readFile(const std::string & fileName,
164169

165170
FileContents contents = std::make_shared<std::vector<unsigned char>>(size);
166171

167-
int fd = open(fileName.c_str(), O_RDONLY);
172+
int fd = open(fileName.c_str(), O_RDONLY | O_BINARY);
168173
if (fd == -1) throw SysError(fmt("opening '", fileName, "'"));
169174

170175
size_t bytesRead = 0;
@@ -375,7 +380,7 @@ static void writeFile(const std::string & fileName, const FileContents & content
375380
{
376381
debug("writing %s\n", fileName.c_str());
377382

378-
int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777);
383+
int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0777);
379384
if (fd == -1)
380385
error("open");
381386

0 commit comments

Comments
 (0)