Skip to content

Commit

Permalink
Re-encode to native just prior to fopen()
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed May 8, 2022
1 parent 8e821c0 commit 68602ec
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/unicode_fopen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#endif
// clang-format on

#ifdef _WIN32
#include <Rinternals.h>

#ifdef _WIN32
#include <windows.h>
#else
#include "cpp11/r_string.hpp"
#endif

// This is needed to support wide character paths on windows
Expand All @@ -40,7 +43,10 @@ inline FILE* unicode_fopen(const char* path, const char* mode) {
MultiByteToWideChar(CP_UTF8, 0, path, -1, buf, len);
out = _wfopen(buf, mode_w);
#else
out = fopen(path, mode);
// cpp11 will have converted the user's path to UTF-8 by now
// but we need to pass the path to fopen() in the native encoding
const char* native_path = Rf_translateChar(cpp11::r_string(path));
out = fopen(native_path, mode);
#endif

return out;
Expand Down

0 comments on commit 68602ec

Please sign in to comment.