ssize_t ret = write(fd, ptr, to_write);
if (ret == -1) {
log_perror("write");
- safe_close(fd);
+ if (close(fd) == -1) {
+ log_perror("close");
+ }
return -1;
}
bool read_tempfile_and_close(int fd, std::string *contents)
{
bool ok = read_tempfile(fd, contents);
- safe_close(fd); // Implicitly deletes the file.
+
+ int ret;
+ do {
+ ret = close(fd); // Implicitly deletes the file.
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret == -1) {
+ log_perror("close");
+ // Can still continue.
+ }
+
return ok;
}
return true;
}
-
-int safe_close(int fd)
-{
- int ret;
- do {
- ret = close(fd);
- } while (ret == -1 && errno == EINTR);
-
- if (ret == -1) {
- log_perror("close()");
- }
-
- return ret;
-}