Skip to content

Commit a04ca83

Browse files
committed
Add O_BINARY flag when opening files to allow compilation for Windows
1 parent 8f5ac59 commit a04ca83

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/patchelf.cc

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

50+
#ifndef O_BINARY
51+
#define O_BINARY 0
52+
#endif
53+
5054
static bool debugMode = false;
5155

5256
static bool forceRPath = false;
@@ -164,7 +168,7 @@ static FileContents readFile(const std::string & fileName,
164168

165169
FileContents contents = std::make_shared<std::vector<unsigned char>>(size);
166170

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

170174
size_t bytesRead = 0;
@@ -375,7 +379,7 @@ static void writeFile(const std::string & fileName, const FileContents & content
375379
{
376380
debug("writing %s\n", fileName.c_str());
377381

378-
int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777);
382+
int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0777);
379383
if (fd == -1)
380384
error("open");
381385

0 commit comments

Comments
 (0)