MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / OutputStream

Method OutputStream

tools/ktx/command.cpp:121–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119// -------------------------------------------------------------------------------------------------
120
121OutputStream::OutputStream(const std::string& filepath, Reporter& report) :
122 filepath(filepath) {
123
124 if (filepath == "-") {
125 #if defined(_WIN32)
126 // Set "stdout" to binary mode
127 const auto setmodeResult = _setmode(_fileno(stdout), _O_BINARY);
128 if (setmodeResult == -1)
129 report.fatal(rc::IO_FAILURE, "Failed to set stdout mode to binary: {}.", setmodeResult);
130 // #else
131 // std::freopen(nullptr, "wb", stdout);
132 #endif
133 file = stdout;
134 } else {
135#if defined(_WIN32)
136 file = _wfopen(DecodeUTF8Path(filepath).c_str(), L"wb");
137#else
138 file = fopen(DecodeUTF8Path(filepath).c_str(), "wb");
139#endif
140 if (!file)
141 report.fatal(rc::IO_FAILURE, "Could not open output file \"{}\": {}.", filepath, errnoMessage());
142 }
143
144 // TODO: Investigate and resolve the portability issue with the C++ streams. The issue will most likely
145 // be in StreambufStream's position reporting and seeking. Currently a fallback is implemented in C above.
146 // if (filepath == "-") {
147 // #if defined(_WIN32)
148 // // Set "stdout" to binary mode
149 // const auto setmodeResult = _setmode(_fileno(stdout), _O_BINARY);
150 // if (setmodeResult == -1)
151 // report.fatal(rc::IO_FAILURE, "Failed to set stdout mode to binary: {}", setmodeResult);
152 // // #else
153 // // std::freopen(nullptr, "wb", stdout);
154 // #endif
155 // activeStream = &std::cout;
156 // } else {
157 // file.open(DecodeUTF8Path(filepath).c_str(), std::ios::binary | std::ios::out);
158 // if (!file)
159 // report.fatal(rc::IO_FAILURE, "Could not open output file \"{}\": {}", filepath, errnoMessage());
160 // activeStream = &file;
161 // }
162}
163
164OutputStream::~OutputStream() {
165 if (file != stdout)

Callers

nothing calls this directly

Calls 4

errnoMessageFunction · 0.70
DecodeUTF8PathFunction · 0.50
fatalMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected