+ bool ok = read_tempfile(fd, contents);
+ safe_close(fd); // Implicitly deletes the file.
+ return ok;
+}
+
+bool read_tempfile(int fd, string *contents)
+{
+ ssize_t ret, has_read;
+
+ off_t len = lseek(fd, 0, SEEK_END);
+ if (len == -1) {
+ log_perror("lseek");
+ return false;
+ }
+
+ contents->resize(len);
+