| 186 | } |
| 187 | |
| 188 | static void send_local_file(struct strbuf *hdr, const char *the_type, |
| 189 | const char *name) |
| 190 | { |
| 191 | char *p = repo_git_path(the_repository, "%s", name); |
| 192 | size_t buf_alloc = 8192; |
| 193 | char *buf = xmalloc(buf_alloc); |
| 194 | int fd; |
| 195 | struct stat sb; |
| 196 | |
| 197 | fd = open(p, O_RDONLY); |
| 198 | if (fd < 0) |
| 199 | not_found(hdr, "Cannot open '%s': %s", p, strerror(errno)); |
| 200 | if (fstat(fd, &sb) < 0) |
| 201 | die_errno("Cannot stat '%s'", p); |
| 202 | |
| 203 | hdr_int(hdr, content_length, sb.st_size); |
| 204 | hdr_str(hdr, content_type, the_type); |
| 205 | hdr_date(hdr, last_modified, sb.st_mtime); |
| 206 | end_headers(hdr); |
| 207 | |
| 208 | for (;;) { |
| 209 | ssize_t n = xread(fd, buf, buf_alloc); |
| 210 | if (n < 0) |
| 211 | die_errno("Cannot read '%s'", p); |
| 212 | if (!n) |
| 213 | break; |
| 214 | write_or_die(1, buf, n); |
| 215 | } |
| 216 | close(fd); |
| 217 | free(buf); |
| 218 | free(p); |
| 219 | } |
| 220 | |
| 221 | static void get_text_file(struct strbuf *hdr, char *name) |
| 222 | { |
no test coverage detected