| 66 | } |
| 67 | |
| 68 | static int fd_read_lines(int fd, char ***namesp) |
| 69 | { |
| 70 | char *buf = NULL; |
| 71 | int err = 0; |
| 72 | off_t size; |
| 73 | |
| 74 | size = lseek(fd, 0, SEEK_END); |
| 75 | if (size < 0) { |
| 76 | err = REFTABLE_IO_ERROR; |
| 77 | goto done; |
| 78 | } |
| 79 | |
| 80 | err = lseek(fd, 0, SEEK_SET); |
| 81 | if (err < 0) { |
| 82 | err = REFTABLE_IO_ERROR; |
| 83 | goto done; |
| 84 | } |
| 85 | |
| 86 | REFTABLE_ALLOC_ARRAY(buf, size + 1); |
| 87 | if (!buf) { |
| 88 | err = REFTABLE_OUT_OF_MEMORY_ERROR; |
| 89 | goto done; |
| 90 | } |
| 91 | |
| 92 | for (off_t total_read = 0; total_read < size; ) { |
| 93 | ssize_t bytes_read = read(fd, buf + total_read, size - total_read); |
| 94 | if (bytes_read < 0 && (errno == EAGAIN || errno == EINTR)) |
| 95 | continue; |
| 96 | if (bytes_read < 0 || !bytes_read) { |
| 97 | err = REFTABLE_IO_ERROR; |
| 98 | goto done; |
| 99 | } |
| 100 | |
| 101 | total_read += bytes_read; |
| 102 | } |
| 103 | buf[size] = 0; |
| 104 | |
| 105 | err = parse_names(buf, size, namesp); |
| 106 | done: |
| 107 | reftable_free(buf); |
| 108 | return err; |
| 109 | } |
| 110 | |
| 111 | int read_lines(const char *filename, char ***namesp) |
| 112 | { |
no test coverage detected