-// Read the state back from the file descriptor made by make_tempfile,
-// and close it.
-CubemapStateProto read_tempfile(int state_fd)
-{
- if (lseek(state_fd, 0, SEEK_SET) == -1) {
- perror("lseek");
- exit(1);
- }
-
- string serialized;
- char buf[4096];
- for ( ;; ) {
- ssize_t ret = read(state_fd, buf, sizeof(buf));
- if (ret == -1) {
- perror("read");
- exit(1);
- }
- if (ret == 0) {
- // EOF.
- break;
- }
-
- serialized.append(string(buf, buf + ret));
- }
-
- close(state_fd); // Implicitly deletes the file.
-
- CubemapStateProto state;
- if (!state.ParseFromString(serialized)) {
- fprintf(stderr, "PANIC: Failed deserialization of state.\n");
- exit(1);
- }
-
- return state;
-}
-