11 int make_tempfile(const std::string &contents)
13 char filename[] = "/tmp/cubemap.XXXXXX";
14 int fd = mkstemp(filename);
20 if (unlink(filename) == -1) {
22 // Can still continue;
25 const char *ptr = contents.data();
26 size_t to_write = contents.size();
27 while (to_write > 0) {
28 ssize_t ret = write(fd, ptr, to_write);
42 bool read_tempfile(int fd, std::string *contents)
44 if (lseek(fd, 0, SEEK_SET) == -1) {
51 ssize_t ret = read(fd, buf, sizeof(buf));
61 contents->append(string(buf, buf + ret));
66 ret = close(fd); // Implicitly deletes the files.
67 } while (ret == -1 && errno == EINTR);
71 // Can still continue.