From a04ca83ad7d8c4f2251cf8956d0d491c8a54e6c2 Mon Sep 17 00:00:00 2001 From: Jago Gyselinck Date: Wed, 6 Apr 2022 15:27:33 +0200 Subject: [PATCH 1/2] Add O_BINARY flag when opening files to allow compilation for Windows --- src/patchelf.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index 0164ead..e785884 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -47,6 +47,10 @@ #define PACKAGE_STRING "patchelf" #endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif + static bool debugMode = false; static bool forceRPath = false; @@ -164,7 +168,7 @@ static FileContents readFile(const std::string & fileName, FileContents contents = std::make_shared>(size); - int fd = open(fileName.c_str(), O_RDONLY); + int fd = open(fileName.c_str(), O_RDONLY | O_BINARY); if (fd == -1) throw SysError(fmt("opening '", fileName, "'")); size_t bytesRead = 0; @@ -375,7 +379,7 @@ static void writeFile(const std::string & fileName, const FileContents & content { debug("writing %s\n", fileName.c_str()); - int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777); + int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0777); if (fd == -1) error("open"); From 676326c0cf2702eb98d2ada876812e63dcfea3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 7 Apr 2022 07:22:02 +0100 Subject: [PATCH 2/2] Update src/patchelf.cc --- src/patchelf.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/patchelf.cc b/src/patchelf.cc index e785884..f1eb11a 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -47,6 +47,7 @@ #define PACKAGE_STRING "patchelf" #endif +// This is needed for Windows/mingw #ifndef O_BINARY #define O_BINARY 0 #endif