Function to open a file if it exists, if not and is requested we will create the file.
| 74 | |
| 75 | /// Function to open a file if it exists, if not and is requested we will create the file. |
| 76 | std::string |
| 77 | open_file(std::string const &filename, std::fstream &fs, std::ios_base::openmode mode = std::ios::in | std::ios::out, |
| 78 | bool create = false) |
| 79 | { |
| 80 | fs.open(filename, mode); |
| 81 | |
| 82 | if (!fs.is_open()) { |
| 83 | if (create) { |
| 84 | fs.clear(); |
| 85 | if (fs.open(filename, std::ios::out); fs.is_open()) { |
| 86 | return {}; |
| 87 | } |
| 88 | } |
| 89 | std::string text; |
| 90 | return swoc::bwprint(text, "We couldn't open '{}': {}", filename, strerror(errno)); |
| 91 | } |
| 92 | return {}; |
| 93 | } |
| 94 | |
| 95 | /// Bunch of mapping flags for the TAGS. |
| 96 | std::string |
no test coverage detected