MCPcopy Create free account
hub / github.com/DISTORTEC/distortos / openFile

Function openFile

source/FileSystem/openFile.cpp:163–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161+---------------------------------------------------------------------------------------------------------------------*/
162
163std::pair<int, FILE*> openFile(FileSystem& fileSystem, const char* const path, const char* const mode)
164{
165 assert(mode != nullptr);
166
167 int flags;
168 {
169 const auto ret = __sflags(_REENT, mode, &flags);
170 assert(ret != 0);
171 }
172
173 std::unique_ptr<File> file;
174 {
175 int ret;
176 std::tie(ret, file) = fileSystem.openFile(path, flags);
177 if (ret != 0)
178 return {ret, {}};
179 }
180
181 assert(file != nullptr);
182
183 auto closeScopeGuard = estd::makeScopeGuard([&file]()
184 {
185 file->close();
186 });
187
188 const auto ret = fopencookie(file.get(), mode, {fileRead, fileWrite, fileSeek, fileClose});
189 if (ret == nullptr)
190 return {errno, {}};
191
192 closeScopeGuard.release();
193 file.release();
194 return {{}, ret};
195}
196
197} // namespace distortos

Callers

nothing calls this directly

Calls 5

makeScopeGuardFunction · 0.85
openFileMethod · 0.80
closeMethod · 0.45
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected