* Map and close the given loose object fd. The path argument is used for * error reporting. */
| 147 | * error reporting. |
| 148 | */ |
| 149 | static void *map_fd(int fd, const char *path, unsigned long *size) |
| 150 | { |
| 151 | void *map = NULL; |
| 152 | struct stat st; |
| 153 | |
| 154 | if (!fstat(fd, &st)) { |
| 155 | *size = xsize_t(st.st_size); |
| 156 | if (!*size) { |
| 157 | /* mmap() is forbidden on empty files */ |
| 158 | error(_("object file %s is empty"), path); |
| 159 | close(fd); |
| 160 | return NULL; |
| 161 | } |
| 162 | map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); |
| 163 | } |
| 164 | close(fd); |
| 165 | return map; |
| 166 | } |
| 167 | |
| 168 | enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, |
| 169 | unsigned char *map, |
no test coverage detected