12 int make_tempfile(const std::string &contents)
14 char filename[] = "/tmp/cubemap.XXXXXX";
15 int fd = mkstemp(filename);
17 log_perror("mkstemp");
21 if (unlink(filename) == -1) {
23 // Can still continue;
26 const char *ptr = contents.data();
27 size_t to_write = contents.size();
28 while (to_write > 0) {
29 ssize_t ret = write(fd, ptr, to_write);
43 bool read_tempfile(int fd, std::string *contents)
46 ssize_t ret, has_read;
48 off_t len = lseek(fd, 0, SEEK_END);
55 contents->resize(len);
57 if (lseek(fd, 0, SEEK_SET) == -1) {
64 while (has_read < len) {
65 ret = read(fd, &((*contents)[has_read]), len - has_read);
72 log(ERROR, "Unexpected EOF!");
81 ret = close(fd); // Implicitly deletes the files.
82 } while (ret == -1 && errno == EINTR);
86 // Can still continue.