| 79 | } |
| 80 | |
| 81 | bool WriteStringToFd(const std::string& content, int fd) { |
| 82 | const char* p = content.data(); |
| 83 | size_t left = content.size(); |
| 84 | while (left > 0) { |
| 85 | ssize_t n = TEMP_FAILURE_RETRY(write(fd, p, left)); |
| 86 | if (n == -1) { |
| 87 | return false; |
| 88 | } |
| 89 | p += n; |
| 90 | left -= n; |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | static bool CleanUpAfterFailedWrite(const std::string& path) { |
| 96 | // Something went wrong. Let's not leave a corrupt file lying around. |
no test coverage detected