Helper to create a file with the given content.
| 57 | |
| 58 | // Helper to create a file with the given content. |
| 59 | void createFile(const std::string& path, const std::string& content) |
| 60 | { |
| 61 | std::cout |
| 62 | << "Creating file: " << path << " with content=" << content << endl; |
| 63 | |
| 64 | const int fd = ::open(path.c_str(), O_CREAT | O_WRONLY, 0644); |
| 65 | if (fd == -1) { |
| 66 | const int error = errno; |
| 67 | std::cout |
| 68 | << "Failed to open file for writing: " << path << "; errno=" << error |
| 69 | << "; " << std::strerror(error) << endl; |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (::write(fd, content.c_str(), content.size()) != content.size()) { |
| 74 | const int error = errno; |
| 75 | std::cout |
| 76 | << "Failed to write content=" << content << " to file=" << path |
| 77 | << "; errno=" << error << "; " << std::strerror(error) << endl; |
| 78 | |
| 79 | // Fall through to close FD. |
| 80 | } |
| 81 | |
| 82 | ::close(fd); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | //============================================================================ |