diff options
| author | Daniil Cherednik <[email protected]> | 2026-05-03 20:47:07 +0200 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2026-05-03 20:47:07 +0200 |
| commit | 412629c19112d97c1ef56a75cdeee06fb3eb7f7f (patch) | |
| tree | e4bb4fab97176b2b703a743014f275dc4f08010c /src | |
| parent | 84c58f18c908defb95494e86d0c7c36750dac01b (diff) | |
Drop FileModeToWide allow-listfix_input_file_path
Widen the ASCII fopen mode string with std::wstring's iterator-pair
constructor instead of maintaining a hand-coded mapping. ASCII (0-127)
codepoints are valid wchar_t code units on Windows, which is the only
alphabet fopen modes use.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/utf8_file.h | 42 |
1 files changed, 2 insertions, 40 deletions
diff --git a/src/utf8_file.h b/src/utf8_file.h index 8ef451f..4ee1787 100644 --- a/src/utf8_file.h +++ b/src/utf8_file.h @@ -19,7 +19,6 @@ #pragma once #include <cstdio> -#include <cstring> #include <stdexcept> #include <string> @@ -43,50 +42,13 @@ inline std::wstring Utf8ToWidePath(const std::string& path) { res.pop_back(); return res; } - -inline const wchar_t* FileModeToWide(const char* mode) { - if (!mode) { - return nullptr; - } - if (std::strcmp(mode, "r") == 0) { - return L"r"; - } - if (std::strcmp(mode, "w") == 0) { - return L"w"; - } - if (std::strcmp(mode, "a") == 0) { - return L"a"; - } - if (std::strcmp(mode, "rb") == 0) { - return L"rb"; - } - if (std::strcmp(mode, "wb") == 0) { - return L"wb"; - } - if (std::strcmp(mode, "ab") == 0) { - return L"ab"; - } - if (std::strcmp(mode, "rb+") == 0 || std::strcmp(mode, "r+b") == 0) { - return L"rb+"; - } - if (std::strcmp(mode, "wb+") == 0 || std::strcmp(mode, "w+b") == 0) { - return L"wb+"; - } - if (std::strcmp(mode, "ab+") == 0 || std::strcmp(mode, "a+b") == 0) { - return L"ab+"; - } - return nullptr; -} #endif inline FILE* FOpenUtf8(const std::string& path, const char* mode) { #ifdef _WIN32 - const wchar_t* wmode = FileModeToWide(mode); - if (!wmode) { - return nullptr; - } const std::wstring wpath = Utf8ToWidePath(path); - return _wfopen(wpath.c_str(), wmode); + const std::wstring wmode(mode, mode + std::char_traits<char>::length(mode)); + return _wfopen(wpath.c_str(), wmode.c_str()); #else return fopen(path.c_str(), mode); #endif |
