10 int make_tempfile(const std::string &contents)
12 char filename[] = "/tmp/cubemap.XXXXXX";
13 int fd = mkstemp(filename);
19 if (unlink(filename) == -1) {
21 // Can still continue;
24 const char *ptr = contents.data();
25 size_t to_write = contents.size();
26 while (to_write > 0) {
27 ssize_t ret = write(fd, ptr, to_write);
41 bool read_tempfile(int fd, std::string *contents)
43 if (lseek(fd, 0, SEEK_SET) == -1) {
50 ssize_t ret = read(fd, buf, sizeof(buf));
60 contents->append(string(buf, buf + ret));
65 ret = close(fd); // Implicitly deletes the files.
66 } while (ret == -1 && errno == EINTR);
70 // Can still continue.