| 161 | +---------------------------------------------------------------------------------------------------------------------*/ |
| 162 | |
| 163 | std::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 |
nothing calls this directly
no test coverage detected