diff options
author | Aras Pranckevicius <aras_p> | 2022-01-22 04:14:01 +0300 |
---|---|---|
committer | Howard Trickey <howard.trickey@gmail.com> | 2022-01-22 04:14:01 +0300 |
commit | 9350005d8b56a831f4c592d58fdf190af64efad4 (patch) | |
tree | 1d25f5a85a241e6872aa64176b71bfc114800195 /source/blender/io/wavefront_obj | |
parent | 1f026a3db90987164a270b0a8104e2c28634d309 (diff) |
Fix T13879 new OBJ exporter not saving files with Unicode characters.
Need to use BLI_fopen instead of fopen.
Diffstat (limited to 'source/blender/io/wavefront_obj')
-rw-r--r-- | source/blender/io/wavefront_obj/exporter/obj_export_io.hh | 3 | ||||
-rw-r--r-- | source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc | 20 |
2 files changed, 14 insertions, 9 deletions
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh index e88a76fc4e8..daae8ae52c8 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh @@ -26,6 +26,7 @@ #include <type_traits> #include "BLI_compiler_attrs.h" +#include "BLI_fileops.h" #include "BLI_string_ref.hh" #include "BLI_utility_mixins.hh" @@ -276,7 +277,7 @@ template<eFileType filetype> class FormattedFileHandler : NonCopyable, NonMovabl FormattedFileHandler(std::string outfile_path) noexcept(false) : outfile_path_(std::move(outfile_path)) { - outfile_ = std::fopen(outfile_path_.c_str(), "w"); + outfile_ = BLI_fopen(outfile_path_.c_str(), "w"); if (!outfile_) { throw std::system_error(errno, std::system_category(), "Cannot open file " + outfile_path_); } diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 5dac913c902..89e1de49511 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -1,10 +1,8 @@ /* Apache License, Version 2.0 */ -#include <fstream> #include <gtest/gtest.h> #include <ios> #include <memory> -#include <sstream> #include <string> #include <system_error> @@ -185,15 +183,21 @@ static std::unique_ptr<OBJWriter> init_writer(const OBJExportParams ¶ms, } } -/* The following is relative to BKE_tempdir_base. */ -const char *const temp_file_path = "output.OBJ"; +/* The following is relative to BKE_tempdir_base. + * Use Latin Capital Letter A with Ogonek, Cyrillic Capital Letter Zhe + * at the end, to test I/O on non-English file names. */ +const char *const temp_file_path = "output\xc4\x84\xd0\x96.OBJ"; static std::string read_temp_file_in_string(const std::string &file_path) { - std::ifstream temp_stream(file_path); - std::ostringstream input_ss; - input_ss << temp_stream.rdbuf(); - return input_ss.str(); + std::string res; + size_t buffer_len; + void *buffer = BLI_file_read_text_as_mem(file_path.c_str(), 0, &buffer_len); + if (buffer != NULL) { + res.assign((const char *)buffer, buffer_len); + MEM_freeN(buffer); + } + return res; } TEST(obj_exporter_writer, header) |