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)
45 ssize_t ret, has_read;
47 off_t len = lseek(fd, 0, SEEK_END);
54 contents->resize(len);
56 if (lseek(fd, 0, SEEK_SET) == -1) {
63 while (has_read < len) {
64 ret = read(fd, &((*contents)[has_read]), len - has_read);
71 fprintf(stderr, "Unexpected EOF!\n");
80 ret = close(fd); // Implicitly deletes the files.
81 } while (ret == -1 && errno == EINTR);
85 // Can still continue.