From e389ca7469162728c37a9d9c7b2ce6cf11c8910e Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 9 Jul 2022 00:00:49 +0100 Subject: [PATCH] Workaround for wrong file permissions from zstd extraction on wasm Signed-off-by: falkTX --- include/common.hpp | 13 +++++++++++++ src/override/common.cpp | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/common.hpp b/include/common.hpp index 327acb4..94102b0 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -30,6 +30,19 @@ #include_next "common.hpp" +// Workaround for wrong file permissions from zstd extraction +#ifdef __EMSCRIPTEN__ +#define fopen fopen_wasm + +extern "C" { +FILE* fopen_wasm(const char* filename, const char* mode); +} + +namespace std { + using ::fopen_wasm; +} +#endif + // Make binary resources work the same no matter the OS #undef BINARY #undef BINARY_START diff --git a/src/override/common.cpp b/src/override/common.cpp index 7bd8b0e..191914e 100644 --- a/src/override/common.cpp +++ b/src/override/common.cpp @@ -34,7 +34,7 @@ #include "DistrhoPluginUtils.hpp" -#if defined ARCH_WIN +#if defined(ARCH_WIN) #include FILE* fopen_u8(const char* filename, const char* mode) { @@ -43,6 +43,15 @@ FILE* fopen_u8(const char* filename, const char* mode) { return _wfopen(rack::string::UTF8toUTF16(filename).c_str(), rack::string::UTF8toUTF16(mode).c_str()); } +#elif defined(DISTRHO_OS_WASM) +#include +#undef fopen + +FILE* fopen_wasm(const char* filename, const char* mode) { + chmod(filename, 0777); + return std::fopen(filename, mode); +} + #endif